有三个ListBox,分别显示三个层分类名称。一级分类ListBox1;二级分类ListBox2;三级分类ListBox3;
其中ListBox3的数据时根据ListBox2的选中项绑定数据,ListBox2的数据是根据ListBox1的选中项绑定数据的。
我用C#在将autoPostBack属性设置为true的情况下实现了这个功能,但是因为每次都要提交服务器,会占用服务器资源,我想不在autoPostBack=true的情况下实现这个功能,但是不知道该如何实现绑定。
是不是应该把数据绑定写在Page_Load里面,要不要用到javascript?谢谢~
其中ListBox3的数据时根据ListBox2的选中项绑定数据,ListBox2的数据是根据ListBox1的选中项绑定数据的。
我用C#在将autoPostBack属性设置为true的情况下实现了这个功能,但是因为每次都要提交服务器,会占用服务器资源,我想不在autoPostBack=true的情况下实现这个功能,但是不知道该如何实现绑定。
是不是应该把数据绑定写在Page_Load里面,要不要用到javascript?谢谢~
解决方案 »
- 菜鸟请问:将GridView绑定到数据源后可自动删除,编辑,但是如何添加一行?
- MVC3(Razor)循环中使用document.write
- 【急】ArrayList 中元素的顺序问题!!!
- 使用模态对话框中的window.returnValue怎么返回中文阿,总提示变量未定义错误?
- 求一个与QQ类似的上翻菜单源码。
- 不知道怎么用这个类?
- 修改web.config文件
- 则么在点击server端控件时,提示"是否确认"的提示,否的话就不提交
- Asp.net 1.1 的页面缓存问题
- 快快快快快快快快快快快快快快快快乐乐乐乐乐乐乐乐乐乐乐乐乐乐乐乐乐乐!!
- 万分紧急~~~2003下配置asp.net网站无法运行,一运行就会导致程序池停止
- 读文件问题!
下面是一个二级的无刷新联动例子,你自己根据XMLHTTP的运用方式,自己先去尝试.原理都是一样的.以下为页面代码:<form id="Form1" method="post" runat="server">
<asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
<asp:DropDownList id="DropDownList2" runat="server"></asp:DropDownList>
<SCRIPT LANGUAGE="JavaScript">
<!--
//以XML求取数据
function XmlPost(obj)
{
var svalue = obj.value;
var webFileUrl = "?brc_id=" + svalue;
var result = "";
var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
xmlHttp.open("POST", webFileUrl, false);
xmlHttp.send("");
result = xmlHttp.responseText;
if(result != "")
{
document.all("DropDownList2").length=0;
var piArray = result.split(",");
for(var i=0;i<piArray.length;i++)
{
var ary1 = piArray[i].toString().split("|");
//alert(ary1[0].toString());
document.all("DropDownList2").options.add(new Option(ary1[1].toString(),ary1[0].toString()));
}
}
else
{
alert(result);
}
}
//-->
</SCRIPT>
</form>以下为后台代码:private System.Data.OleDb.OleDbConnection conn;private DataTable get_dt(string sql)
{
string connstr = "Provider=MSDAORA.1;Password=aqjc;User ID=aqjc;Data Source=aqjc";
this.conn = new OleDbConnection(connstr);
this.conn.Open();
OleDbCommand myOleDbCommand = new OleDbCommand(sql,this.conn);
OleDbDataAdapter myData = new OleDbDataAdapter(myOleDbCommand); DataSet myDataset = new DataSet();
try
{
myData.Fill(myDataset);
}
catch(Exception ex)
{
throw ex;
} this.conn.Close();
return myDataset.Tables[0];
}private void Page_Load(object sender, System.EventArgs e)
{
string brc_id = this.Request.QueryString["brc_id"];
if(brc_id + "a" != "a")
{
this.down2_bind(brc_id);
} if(!this.IsPostBack)
{
this.down1_bind();
}
}/// <summary>
/// 返回第2个下拉框需要的值给xmlhttp
/// </summary>
/// <param name="brc_id"></param>
private void down2_bind(string brc_id)
{
string mystr = "";
string sql = "select brc_id,brc_name from asm_branch where brc_parentid = '" + brc_id + "'";
DataTable mytab = this.get_dt(sql); if(mytab.Rows.Count != 0)
{
for(int i=0;i<mytab.Rows.Count;i++)
{
mystr += "," + mytab.Rows[i][0].ToString() + "|" + mytab.Rows[i][1].ToString();
}
mystr = mystr.Substring(1);
}
this.Response.Write(mystr);
this.Response.End();
}/// <summary>
/// 绑定第一个下拉框
/// </summary>
private void down1_bind()
{
string sql = "select brc_id,brc_name from asm_branch where brc_level = '1'";
DataTable mytab = this.get_dt(sql);
this.DropDownList1.DataSource = mytab;
this.DropDownList1.DataValueField = "brc_id";
this.DropDownList1.DataTextField = "brc_name";
this.DropDownList1.DataBind();
this.DropDownList1.Attributes.Add("onchange","XmlPost(this);");
}