簡體   English   中英

下拉列表選定的索引更改在“更新”面板中不起作用

[英]Drop Down List Selected Index changed not working in Update panel

我在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中,仍然沒有成功。

我還添加了triggre來更新面板2,但沒有增益,

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

我在使用按鈕填充DropDownList而不是PAGE LOAD METHOD請在回答之前閱讀。 謝謝

檢查數據以填充Page_Load事件中的DropDownList ,並始終檢查IspostBack

if(!IsPostBack)
{
 //DropDownList configuration
}

使用EnableViewState

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

希望它能幫到你。

我遇到過同樣的問題。 我的問題是我的ListItems的值都是一樣的:D

<asp:DropDownList ID="ddlFilterLogins" runat="server" Visible="true" AutoPostBack="true">
    <asp:ListItem Value="0" Text="All"></asp:ListItem>
    <asp:ListItem Value="0" Text="Some"></asp:ListItem>
    <asp:ListItem Value="0" Text="Some more"></asp:ListItem>
</asp:DropDownList>

它應該是這樣的:

<asp:DropDownList ID="ddlFilterLogins" runat="server" Visible="true" AutoPostBack="true">
    <asp:ListItem Value="0" Text="All"></asp:ListItem>
    <asp:ListItem Value="1" Text="Some"></asp:ListItem>
    <asp:ListItem Value="2" Text="Some more"></asp:ListItem>
</asp:DropDownList>

希望這可以幫助。 這有時候很難找到:)

請在Page_Load()初始化時檢查是否回發。 如果不這樣做,您將始終設置默認值,這將替換事件中設置的值。

if(!IsPostBack)
{
//DropDownList configuration
}

您可以使用Init事件而不是SelectIndexChanged。 它對我來說很好。 希望你明白我的意思。

對我來說這也是一個有線問題。 最后這是因為下拉列表中的列表項相同,如下所示。 在開發過程中,您可以使用相同的項目進行測試。 改變它們。

<asp:ListItem>Business</asp:ListItem>
<asp:ListItem>Business</asp:ListItem>
<asp:ListItem>Business</asp:ListItem>
<asp:ListItem>Business</asp:ListItem>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM