当前第2页 返回上一页
1 2 3 4 5 6 7 8 9 10 11 12 | <span style= "font-family:KaiTi_GB2312;font-size:18px;" >
protected void DropDownList1_SelectedIndexChanged( object sender, EventArgs e)
{
this .ListBox1.Items.Clear();
SqlConnection con2 = DB.createConnection();
SqlCommand cmd1 = new SqlCommand( "select * from city where proID=" + this .DropDownList1.SelectedValue, con2);
SqlDataReader sdr1 = cmd1.ExecuteReader();
while (sdr1.Read())
{
this .ListBox1.Items.Add( new ListItem(sdr1.GetString(2),sdr1.GetInt32(0).ToString()));
}
}</span>
|
运行文件,效果图如下所示
这里河北省的城市我没有添加完整,只是为了实现两级联动的功能,相比前两篇博客中Web控件GridView和Repeater的使用,GridView和Repeater功能虽然是相当强大,但是不同的控件有不同的用途,在这里,杀鸡焉用牛刀?
以上就是《ASP.NET》数据绑定―DropDownList、ListBox的图文代码详解的详细内容!
返回前面的内容
相关阅读 >>
详解《asp.net》数据绑定―datalist
详细介绍《asp.net》数据绑定――gridview
《asp.net》数据绑定―dropdownlist、listbox的图文代码详解
asp.net数据绑定控件详解(图文)
《asp.net》数据绑定―datalist实践篇的图文代码详解
更多相关阅读请进入《数据绑定》频道 >>
清华大学出版社
作者:[美]克里斯琴·内格尔(Christian Nagel)著。出版时间:2019年3月。
转载请注明出处:木庄网络博客 » 《ASP.NET》数据绑定―DropDownList、ListBox的图文代码详解