Reputation: 3958
I have the following asp dropdown:
<asp:DropDownList ID="ArticleCategories" runat="server" AppendDataBoundItems="true" CssClass="ArticleCategoriesDropDown" onselectedindexchanged="mCategoryItemSelected" AutoPostBack="True">
<asp:ListItem Text="Select Category" Value="" />
</asp:DropDownList>
Once a selection has been made, and the data loaded, I want to set the value in the dropdown to display the value chosen by the user.
I am doing this by:
ArticleCategories.SelectedValue = CategoryID.ToString();
This works fine the first time, but from then the page is stuck on that selection, as the selected value gets loaded before the new value can load.
I have tried disabling the itemchangelistener by:
ArticleCategories.SelectedIndexChanged += new EventHandler(doNothing);
But that does not work.
I have also tried to disable postback which also does not work.
Any ideas?
Upvotes: 0
Views: 356
Reputation: 4489
Hey before selecting another item from Dropdown
you should clear previous selection then selected another one.
ArticleCategories.ClearSelection();
Hope it helps you.
Upvotes: 0
Reputation: 78
You can do Autopostback= false
<asp:DropDownList ID="ArticleCategories" runat="server" AppendDataBoundItems="true" CssClass="ArticleCategoriesDropDown" onselectedindexchanged="mCategoryItemSelected" AutoPostBack="False">
<asp:ListItem Text="Select Category" Value="" />
</asp:DropDownList>
Upvotes: 0
Reputation: 1147
You should only set the selection when loading the page the first time. In ASP.NET, you can achieve this by checking the IsPostBack
property:
if(!IsPostBack)
{
ArticleCategories.SelectedValue = CategoryID.ToString();
}
Upvotes: 1