asp.net利用listbox查看内部列
protected void listbox1_selectedindexchanged(object sender, eventargs e)
{
this.listbox2.items.clear();
string s = "select * from class where sid='" + this.listbox1.selectedvalue + "'";
sqlconnection ccc = new sqlconnection();
ccc.connectionstring = configurationmanager.connectionstrings["strcnn"].connectionstring;
sqlcommand cmm = new sqlcommand(s, ccc);
ccc.open();//调用
sqldatareader myr;
myr = cmm.executereader();
while (myr.read())
{
this.listbox2.items.add(new listitem(myr["classname"].tostring(), myr["id"].tostring()));
}
}代码写在listbox1的selectedindexchanged属性里面
然后autopostback为ture就可以上传到服务器
然后在里面写代码 获取listbox1的选中项 从数据库获取数据 这时候就看着上班代码 就可以更新了
摘自 liuningshiwoa的专栏