怪:用javascript移动listbox的项但是更新数据库时lb_Trust_Major.Items.Count没有变化!
我有2个listbox:lb_NotTrust_Major 和 lb_Trust_Major ,我用javascriot实现他们之间的项的移动,但是我在更新发现lb_Trust_Major.Items.Count的值没有变化。大家帮我看看到底时怎样回事吧!谢谢大家~string js = "<script language=javascript> function change()";
js += "{";
js += "var lb_Trust_Major = document.getElementById('" + lb_Trust_Major.ClientID + "');";
js += "var lb_NotTrust_Major = document.getElementById('" + lb_NotTrust_Major.ClientID + "');";
js += "var addOption=document.createElement('option');";
js += " var index1; ";
js += "if(lb_Trust_Major.length==0)return(false);";
js += " index1=lb_Trust_Major.selectedIndex; ";
js += " if(index1<0)return(false);";
js += " addOption.text=lb_Trust_Major.options(index1).text; ";
js += "addOption.value=lb_Trust_Major.value; ";
js += "lb_NotTrust_Major.add(addOption); ";
js += "lb_Trust_Major.remove (index1)";
js += "}";
js += "</script>";
//注册该 javascript ;
this.RegisterStartupScript("", js);
//为控件添加双击事件;
this.lb_Trust_Major.Attributes.Add("onDblClick", "change();");
------------------------------------------------------】
protected void bt_UpdateDB_Click(object sender, EventArgs e)
{
string[] strSQLs;//字符串数组,用于保存查询语句
strSQLs = new string[lb_Trust_Major.Items.Count + 1];
strSQLs[0] = "delete from app_rel_FriendMajor where MasterMajorCode = '" + ddl_Main_Major.SelectedValue.ToString() + "'";
for (int i = 1; i < lb_Trust_Major.Items.Count + 1; i++)
{
strSQLs[i] = "insert into app_rel_FriendMajor (MasterMajorCode, TrustMajorCode) " +
" values ( '" + ddl_Main_Major.SelectedValue.ToString() + "', '" + lb_Trust_Major.Items[i - 1].Value.ToString() + "') ";
}
int n = Database.ExecuteSqls(strSQLs);
Response.Write("<Script>alert('修改成功!');</Script>");//11.12
}
调试发现lb_Trust_Major.Items.Count 的值没有变化,那么我的移动就是没有作用。不知道是什么原因,高手帮我看看吧!小弟感激不尽!