ASP.NET DropDownListCheckBox使用示例(解决回发问题)
程序员文章站
2024-02-29 13:40:28
这个是根据ligerui改的,解决了回发问题 资料地址 http://ligerui.com/demos/combobox/comboboxmul.htm 具体...
这个是根据ligerui改的,解决了回发问题
资料地址
http://ligerui.com/demos/combobox/comboboxmul.htm
具体代码
<%@ page language="c#" autoeventwireup="true" codefile="checkboxlist.aspx.cs" inherits="checkboxlist" %>
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title></title>
<link href="lib/ligerui/skins/aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<script src="lib/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="lib/ligerui/js/core/base.js" type="text/javascript"></script>
<script src="lib/ligerui/js/plugins/ligercheckbox.js" type="text/javascript"></script>
<script src="lib/ligerui/js/plugins/ligerresizable.js" type="text/javascript"></script>
<script src="lib/ligerui/js/plugins/ligercombobox.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
var manager;
$.get("checkboxhandle.ashx?tem=" + math.random() + "&selectvalue=" + $("#hiddenfield1").val(), function (value) {
if (value.lastindexof("[") >= 0) {
$("#json").val(value);
var data = eval('(' + value + ')');
manager = $("#test1").ligercombobox({
isshowcheckbox: true, ismultiselect: true,
data: data, valuefieldid: 'test3', onselected: function (newvalue) {
//这个是用于在后台获取的
$("#hiddenfield1").val(newvalue);
}
});
} else {
//解决回发问题
var data = eval('(' + $("#json").val() + ')');
manager = $("#test1").ligercombobox({
isshowcheckbox: true, ismultiselect: true,
data: data, valuefieldid: 'test3', onselected: function (newvalue) {
//这个是用于在后台获取的
$("#hiddenfield1").val(newvalue);
}
});
manager.selectvalue(value);
}
});
});
function clickee() {
alert($("#test3").val());
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="text" id="test1" />
<asp:hiddenfield id="hiddenfield1" clientidmode="static" runat="server" />
<asp:hiddenfield id="json" clientidmode="static" runat="server" />
<asp:button id="button1" onclick="button1_click" onclientclick="clickee();" runat="server" text="获取" />
<asp:label id="label1" runat="server" text="label"></asp:label>
</div>
</form>
</body>
</html>
<p>using system;
using system.collections.generic;
using system.linq;
using system.web;
using system.web.ui;
using system.web.ui.webcontrols;</p><p>public partial class checkboxlist : system.web.ui.page
{
protected void page_load(object sender, eventargs e)
{</p><p> }
protected void button1_click(object sender, eventargs e)
{
this.label1.text = this.hiddenfield1.value;
}
}</p>
<p><%@ webhandler language="c#" class="checkboxhandle" %></p><p>using system;
using system.web;
using system.collections.generic;</p><p>public class checkboxhandle : ihttphandler {
public void processrequest (httpcontext context) {
context.response.contenttype = "text/plain";
string select = context.request.querystring["selectvalue"].tostring();
if (string.isnullorempty(select))
{
list<type> list = new list<type>();
list.add(new type { id = 1, name = "sam" });
list.add(new type { id = 2, name = "tom" });
list.add(new type { id = 3, name = "jim" });
context.response.write(jsonhelper.getjsonstring(list));
}
else
{
//解决回发问题
context.response.write(select);
}
}
public bool isreusable {
get {
return false;
}
}</p><p>}</p>
资料地址
http://ligerui.com/demos/combobox/comboboxmul.htm
具体代码
复制代码 代码如下:
<%@ page language="c#" autoeventwireup="true" codefile="checkboxlist.aspx.cs" inherits="checkboxlist" %>
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title></title>
<link href="lib/ligerui/skins/aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<script src="lib/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="lib/ligerui/js/core/base.js" type="text/javascript"></script>
<script src="lib/ligerui/js/plugins/ligercheckbox.js" type="text/javascript"></script>
<script src="lib/ligerui/js/plugins/ligerresizable.js" type="text/javascript"></script>
<script src="lib/ligerui/js/plugins/ligercombobox.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
var manager;
$.get("checkboxhandle.ashx?tem=" + math.random() + "&selectvalue=" + $("#hiddenfield1").val(), function (value) {
if (value.lastindexof("[") >= 0) {
$("#json").val(value);
var data = eval('(' + value + ')');
manager = $("#test1").ligercombobox({
isshowcheckbox: true, ismultiselect: true,
data: data, valuefieldid: 'test3', onselected: function (newvalue) {
//这个是用于在后台获取的
$("#hiddenfield1").val(newvalue);
}
});
} else {
//解决回发问题
var data = eval('(' + $("#json").val() + ')');
manager = $("#test1").ligercombobox({
isshowcheckbox: true, ismultiselect: true,
data: data, valuefieldid: 'test3', onselected: function (newvalue) {
//这个是用于在后台获取的
$("#hiddenfield1").val(newvalue);
}
});
manager.selectvalue(value);
}
});
});
function clickee() {
alert($("#test3").val());
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="text" id="test1" />
<asp:hiddenfield id="hiddenfield1" clientidmode="static" runat="server" />
<asp:hiddenfield id="json" clientidmode="static" runat="server" />
<asp:button id="button1" onclick="button1_click" onclientclick="clickee();" runat="server" text="获取" />
<asp:label id="label1" runat="server" text="label"></asp:label>
</div>
</form>
</body>
</html>
复制代码 代码如下:
<p>using system;
using system.collections.generic;
using system.linq;
using system.web;
using system.web.ui;
using system.web.ui.webcontrols;</p><p>public partial class checkboxlist : system.web.ui.page
{
protected void page_load(object sender, eventargs e)
{</p><p> }
protected void button1_click(object sender, eventargs e)
{
this.label1.text = this.hiddenfield1.value;
}
}</p>
复制代码 代码如下:
<p><%@ webhandler language="c#" class="checkboxhandle" %></p><p>using system;
using system.web;
using system.collections.generic;</p><p>public class checkboxhandle : ihttphandler {
public void processrequest (httpcontext context) {
context.response.contenttype = "text/plain";
string select = context.request.querystring["selectvalue"].tostring();
if (string.isnullorempty(select))
{
list<type> list = new list<type>();
list.add(new type { id = 1, name = "sam" });
list.add(new type { id = 2, name = "tom" });
list.add(new type { id = 3, name = "jim" });
context.response.write(jsonhelper.getjsonstring(list));
}
else
{
//解决回发问题
context.response.write(select);
}
}
public bool isreusable {
get {
return false;
}
}</p><p>}</p>