关于下拉列表框的数据绑定

来源:百度知道 编辑:UC知道 时间:2024/05/30 07:40:32
在net中,在c#环境下,怎么让下拉列表框和一个数组绑定

我提供一个思路
aspx文件里面
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
cs文件page_load里面
if(!IsPostBack)
{
string[] s="some strings";
foreach(string ss in s)
DropDownList1.Items.Add(ss);
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e){
页面回发以后你的代码
}
关键是dropdownlist的属性AutoPostBack要设置为true,这个是指页面是否自动回发,OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged",这个是指你的选择改变了以后要做的事情