有一个表 课程表(课程编号,课程名称)
有两个下拉列表 DropDownList1 和DropDownList2 两个列表框都与课程表进行了绑定
其中DropDownList1 中显示的内容是课程编号,DropDownList2 中显示的课程名称,
现在我想让DropDownList2 中显示的内容随着DropDownList1中内容的变化而变化,该如何实现呢?请高手帮忙,C#语言
有两个下拉列表 DropDownList1 和DropDownList2 两个列表框都与课程表进行了绑定
其中DropDownList1 中显示的内容是课程编号,DropDownList2 中显示的课程名称,
现在我想让DropDownList2 中显示的内容随着DropDownList1中内容的变化而变化,该如何实现呢?请高手帮忙,C#语言
当DropDownList1 选中的值发生改变的时候,后台代码控制
DropDownList2 的 Data Source
根据DropDownList1选中的值从新帮定DropDownList2值
DropDownList2.selectedindex=DropDownList1.selectedindex;
this.DropDownList1.DataTextField = "课程编号";
this.DropDownList1.DataValueField = "课程名称";
this.DropDownList2.DataTextField = "课程名称";
this.DropDownList2.DataValueField = "课程编号";
第二步:双击DropDownList1给DropDownList1添加DropDownList1_SelectedIndexChanged事件,记住要选择
DropDownList1的AutoPostBack为true第三步:在事件里面写
this.DropDownList2.SelectedValue = this.DropDownList1.SelectedItem.Text;
string s = DropDownList1.text根据获取的s的值,然后去按照你想要的去获取DropDownList2的值,
在DropDownList2绑定前,把DropDownList2清空。
DropDownList2。clear();