简体   繁体   English

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

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

I have a drop down list in UpdatePanel_2, it gets populated when Button_1 is clicked in UpdatePanel_1. 我在UpdatePanel_2中有一个下拉列表,当在UpdatePanel_1中单击Button_1时,它会被填充。

My ddlist markup is, 我的ddlist标记是,

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

then code behind is, 然后代码背后是,

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

I also tried putting AutoPostback=true to my DropDownList, still no success. 我也尝试将AutoPostback = true放到我的DropDownList中,仍然没有成功。

I also added triggre to update panel 2 but no gain, 我还添加了triggre来更新面板2,但没有增益,

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

I am populating DropDownList using a button not PAGE LOAD METHOD PLEASE READ before answering. 我在使用按钮填充DropDownList而不是PAGE LOAD METHOD请在回答之前阅读。 Thanks 谢谢

Check the data to populate the DropDownList in the Page_Load event and always check IspostBack : 检查数据以填充Page_Load事件中的DropDownList ,并始终检查IspostBack

if(!IsPostBack)
{
 //DropDownList configuration
}

Use EnableViewState : 使用EnableViewState

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

Hope it helps you. 希望它能帮到你。

I had the same issue. 我遇到过同样的问题。 My problem was that the values of my ListItems were all the same :D 我的问题是我的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>

It should be like this: 它应该是这样的:

<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>

Hope this helps. 希望这可以帮助。 This might be hard to find sometimes :) 这有时候很难找到:)

Please, when you initialize it in Page_Load() check if not is postback. 请在Page_Load()初始化时检查是否回发。 If you don't do it, you will always set the default value, and this replaces the value setted in the event. 如果不这样做,您将始终设置默认值,这将替换事件中设置的值。

if(!IsPostBack)
{
//DropDownList configuration
}

You can use Init event instead of SelectIndexChanged. 您可以使用Init事件而不是SelectIndexChanged。 It worked fine for me. 它对我来说很好。 Hope you got my point. 希望你明白我的意思。

It was also a wired problem for me. 对我来说这也是一个有线问题。 finally It was because of identical listitems in the dropdown as shown below. 最后这是因为下拉列表中的列表项相同,如下所示。 during development you may use same items just for testing. 在开发过程中,您可以使用相同的项目进行测试。 change them. 改变它们。

<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.

相关问题 下拉列表未触发索引更改事件 - Drop Down List not triggering Index changed event 动态下拉列表的选定“索引已更改”事件始终返回第一个值 - Dynamic drop down list's selected Index Changed event always return the first value 不会针对在运行时创建的下拉列表触发选定的索引更改事件 - doesn't fire selected index changed event for a drop down list created on run time 获取选定的下拉列表索引 - Getting the selected index of drop down list 两次更新面板和下拉列表数据绑定-生命周期 - Update Panel and Drop Down List databinding twice - lifecycle 回传后保存下拉列表值并设置所选索引 - Saving drop down list value and set selected index after postback asp.net中下拉列表的选定索引更改事件 - Selected Index change event of drop down list in asp.net 如何在asp.net中保存下拉列表选择的索引? - How to save the drop down list selected index in asp.net? 如何使用asp.net中的另一个下拉列表更改下拉列表选择的索引和可见性? - How to change drop down list selected index and visibility using another drop down list in asp.net? 将所选项目分配给更新“多个”的下拉列表 - Assigning selected items to drop-down list on update "multiple"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM