markup:
hey for first index to add all not required to add. you need to insert on particular index number
MyList.Items.Insert(0, "ALL");
Yes you are missing to add drop down list Autopostback=true..
Please try with following in your .aspx page
Your code is probably executing after postback too, clearing the box, hence losing selection and all.
If so, try wrapping the code in something like if( !Page.IsPostBack ) { ... }
.
If you're databinding in Page_Load
, you're essentially also resetting the SelectedItem.
You should wrap whatever binding code that exists in Page_Load
inside an if(!IsPostBack)
block.
if(!Page.IsPostBack)
{
// Your binding code here ...
}
So this answer is the "obvious" solution to the most common cause. However, there is one more surprising issue that can cause this! My list values came from a database and the values had linefeed and carriage return: "\r\n". These values look like an innocent space, but actually they are not! My solution was to remove these hidden Char values. Hope it helps.