protected void ListBox
_SelectedIndexChanged(object sender
EventArgs e)
{
this
ListBox
Items
Clear()
string s =
select * from class where sid=
+ this
ListBox
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
ListBox
Items
Add(new ListItem(myr[
classname
]
ToString()
myr[
id
]
ToString()))
}
}代碼寫在listbox
的SelectedIndexChanged屬性裡面
然後autopostback為ture就可以上傳到服務器
然後在裡面寫代碼 獲取listbox
的選中項 從數據庫獲取數據 這時候就看著上班代碼 就可以更新了
From:http://tw.wingwit.com/Article/program/ASP/201311/21687.html