c# – 下拉列表所选索引在“更新”面板中更改为无效

前端之家收集整理的这篇文章主要介绍了c# – 下拉列表所选索引在“更新”面板中更改为无效前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在UpdatePanel_2中有一个下拉列表,当在UpdatePanel_1中点击Button_1时,它将被填充.

我的ddlist标记是,

<asp:DropDownList id="drop1" runat="server"  EnableViewState="true" AutoPostBack="true" OnSelectedIndexChanged="Drop1_SelectedIndexChanged" />

那么后面的代码就是,

protected void Drop1_SelectedIndexChanged(object sender,EventArgs e)
        { }

我也尝试将AutoPostback = true放在我的DropDownList上,仍然没有成功.

我还添加了triggerre来更新面板2,但没有收获,

<Triggers>
    <asp:AsyncPostbackTrigger ControlID="drop1" EventName="SelectedIndexChanged" />
</Triggers>

我正在填充DropDownList使用一个按钮,而不是PAGE LOAD METHOD请在回答之前阅读.
谢谢

解决方法

@H_301_22@ 检查数据以填充Page_Load事件中的DropDownList,并始终检查IspostBack:
if(!IsPostBack)
{
 //DropDownList configuration
}

使用EnableViewState:

<asp:DropDownList ID="ddlAddDepPlans" runat="server" AutoPostBack="true" EnableViewState="true" />

希望它能帮助你.

原文链接:https://www.f2er.com/csharp/92598.html

猜你在找的C#相关文章