[英]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.