dropdownlist autopostback?
below is my dropdownlist with autopostback true now when i selec开发者_运维百科t prefix1 it gives me a post back but when i select it again it doesnt. I have to select prefix2 item first and then go back to prefix1 for it to postback again. Its like as if its postbacking only with SeletedIndexChange
.
I need postback evrytime I choose in my dropdownlist even if its the same item:
<asp:DropDownList runat="server" ID="lstFilePrefix1" AutoPostBack="True"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" >
<asp:ListItem Text="Prefix1" Value="Prefix1" />
<asp:ListItem Text="Prefix2" Value="Prefix2" />
<asp:ListItem Text="Prefix3" Value="Prefix3" />
<asp:ListItem Text="Prefix1 and Prefix2" Value="Prefix1 and Prefix2" />
<asp:ListItem Text="Prefix2 and Prefix3" Value="Prefix2 and Prefix3" />
</asp:DropDownList>
As the dropdownlist behviour, on selected index change, postback occur, you need to change your control selection, you can use checkbox control for that
<asp:DropDownList runat="server" ID="lstFilePrefix1" AutoPostBack="True"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" >
As you should have noticed the event handler is OnSelectedIndexChanged :) So if you select one element and then click it again, the index hasnt changed at all! for it to fire, the index has to change. I think what you want is not possible through DDL
The basic nature/behavior of a drop down control is that items displayed for user selection. When user selected an item and again selecting the same item doesn't make sense to fire OnSeletedIndexChange event. In fact, there is no change in the ITEM INDEX
If this clarifies your question, please mark it.
well, as the method name indicates, the post back will happen only when the selected index changes. If you want to post back each time you select, you may need to use the Html attribute "onclick", writing some javascript function and do the postback yourself
精彩评论