我在页面加载的时候动态绑定select控件
select控件的值是通过后台程序动态绑定的
部分代码如下:
foreach (DataRow dr in ds.Tables[0].Rows)
{
strDLHList += "ddDest.options.add(new Option('" + dr["ID1"].ToString() + "','" + dr["名称"].ToString() + "'));";
}string strScript = "<script language=\"javascript\">"
+ "function GetDLHList(){ "
+ "var ddDest = document.getElementById('slDLH');"
+ strDLHList
+ "}"
+ "</script>";if (!ClientScript.IsClientScriptBlockRegistered("GetDLHList"))
ClientScript.RegisterClientScriptBlock(this.GetType(), "GetDLHList", strScript);
我在前台加上<body onload="GetDLHList();">
我这样做在页面第一次加载的时候可以动态绑定select控件的值
但是当我点击页面上的一个按钮后,页面重新加载了,select控件上的值清空了
请问我要怎么做才能保持select控件的值?
select控件的值是通过后台程序动态绑定的
部分代码如下:
foreach (DataRow dr in ds.Tables[0].Rows)
{
strDLHList += "ddDest.options.add(new Option('" + dr["ID1"].ToString() + "','" + dr["名称"].ToString() + "'));";
}string strScript = "<script language=\"javascript\">"
+ "function GetDLHList(){ "
+ "var ddDest = document.getElementById('slDLH');"
+ strDLHList
+ "}"
+ "</script>";if (!ClientScript.IsClientScriptBlockRegistered("GetDLHList"))
ClientScript.RegisterClientScriptBlock(this.GetType(), "GetDLHList", strScript);
我在前台加上<body onload="GetDLHList();">
我这样做在页面第一次加载的时候可以动态绑定select控件的值
但是当我点击页面上的一个按钮后,页面重新加载了,select控件上的值清空了
请问我要怎么做才能保持select控件的值?
if(!ispostback)
{
//绑定select控件
}
为什么用客户端控件哦...
顺便问一下,你说的清空是什么意思?是你之前选择的值清空了还是select控件的所有值都没了?
2.采用ajax,局部刷新页面
if(!ispostback)
{
绑定值;
}
为什么不用DropDownList是因为DropDownList会刷新页面
影响操作速度
清空的意思是select控件的所有值都没了
不过我现在换另外一种方式实现了
感谢大家的热心回答!