C# DropDownList:已选择索引已更改请勿激发
我在页面加载中填写ASP DropdownlistC# DropDownList:已选择索引已更改请勿激发,c#,asp.net,C#,Asp.net,我在页面加载中填写ASP Dropdownlist protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { for (int i = 0; i < _maxStationsAnz; i++) { String s
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
for (int i = 0; i < _maxStationsAnz; i++)
{
String stations = arrayList[1];
_allData = stations.Split(Convert.ToChar("/"));
_data = _allData[i].Split(Convert.ToChar(";"));
ddWeatherstations.Items.Add(_data[0]);
}
}
当我设置断点并运行程序并更改dropdownlist的值时,什么也不会发生。您需要将dropdownlist
ddWeatherstations
的AutoPostBack
属性设置为True
试试这个:
<asp:DropDownList ID="ddWeatherstations" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="ddWeatherstations_SelectedIndexChanged">
</asp:DropDownList>
您需要设置属性
AutoPostBack=“true”
,但每次您选择不同的DropDownList索引时,这将回发所有页面,因此我建议您将DropDownList放在AJAX更新面板中
<asp:DropDownList ID="ddWeatherstations" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="ddWeatherstations_SelectedIndexChanged">
</asp:DropDownList>