I am using DropDownList inside Updatepanel with its autopost back property set to true, its working fine except when it has SelectedValue=0(ie SelectedIndex=0)
here's my drop down list
<asp:UpdatePanel ID="panel" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddFilter" EnableViewState="false" runat="server" Style="width: 168px;
border: none;" OnSelectedIndexChanged="ddComapanyFilter_SelectedIndexChanged"
AutoPostBack="true">
<asp:ListItem Text="All" Value="0"></asp:ListItem>
<asp:ListItem Text="Flagged" Value="1"></asp:ListItem>
<asp:ListItem Text="New" Value="2"></asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
and this is my SelectedIndexChangedEvent
protected void ddComapanyFilter_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddComapanyFilter.SelectedValue == "0")//All
{
//code
}
else if (ddComapanyFilter.SelectedValue == "1")//Flagged
{
//code
}
else if (ddComapanyFilter.SelectedValue == "2")//New
{
//code
}
}
When I select New or Flagged it works fine, but when I again select All,it don't do any thing,I have tried debugging it,in case of All its not hitting the code.
I tried by replacing my drop down code with this
<asp:DropDownList ID="ddFilter" EnableViewState="false" runat="server" Style="width: 168px;
border: none;" OnSelectedIndexChanged="ddComapanyFilter_SelectedIndexChanged"
AutoPostBack="true">
<asp:ListItem Text="All" Value="1"></asp:ListItem>
<asp:ListItem Text="Flagged" Value="2" Selected="True"></asp:ListItem>
<asp:ListItem Text="New" Value="3"></asp:ListItem>
</asp:DropDownList>
Now When I am selecting Flagged,after selecting New or All, its not hitting
This is a known issue in dropdownlist, always first list item doesn't fire that's why you can add a dummy listitem at the beginning like "Select.." or what ever you want to make it work
<asp:UpdatePanel ID="panel" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddFilter" EnableViewState="false" runat="server" Style="width: 168px;
border: none;" OnSelectedIndexChanged="ddComapanyFilter_SelectedIndexChanged"
AutoPostBack="true">
<asp:ListItem Text="whatever" value=""></asp:ListItem>
<asp:ListItem Text="All" Value="0"></asp:ListItem>
<asp:ListItem Text="Flagged" Value="1"></asp:ListItem>
<asp:ListItem Text="New" Value="2"></asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.