C# – Asp.net dynamic dropdownlist

asp.netcdrop-down-menuviewstate

I want to create a dynamic DropDownList in ASP.NET, but after postback the DropDownList loses the selected value. Recreating the control on postback has no effect (ViewState, same ID).

Im wondering if the ViewState of the DropDownList is not working. I've created dynamic TextBoxes before, and they retain the value after postback.

I'm thinking to get the value from the form post like in this article:

http://www.aspsnippets.com/Articles/Creating-Dynamic-DropDownList-Controls-in-ASP.Net.aspx

Is this a common solution to this problem?

Best Answer

If you're not, you should be dynamically creating the drop-down on Init, and then you can read/write their properties on or after Load. Have a look at this article: http://www.4guysfromrolla.com/articles/092904-1.aspx which describes it in more detail.