i have only one element in drop downlist so selection index change is not working... the datasource is given to run time... if it was on designing time i can give the select one list item... but at run time what should i do????????
Asked
Active
Viewed 1,239 times
3 Answers
1
if i've understood correctly your problem you can you add an empty item at design time , set the append databound item to true and selected property of the empty item to true
-
i have to fill the dropdownlist on every submit... so by append data bound.. the same name is coming again and again – Sheetal Inani Oct 12 '10 at 07:58
-
yes, i should have warned you,if you refresh the items collection every time you must clear it when you start to rebuild, add the empty item and set its selected property to true. If i remember correctly , you must also set the autopostback to true if you want to see the selectedindexchange on server side. And beware also of ajax components if you have put it into an update panel with some triggering conditions – Oct 12 '10 at 08:09
-
how to add an empty item runtime????????????? – Sheetal Inani Oct 12 '10 at 08:12
-
comboBox1.Items.Clear(); – yonan2236 Oct 12 '10 at 08:18
-
i think this post answer your question : http://stackoverflow.com/questions/267064/asp-net-add-blank-item-at-top-of-dropdownlist – Oct 12 '10 at 08:19
-
comboBox1.Items.Add("Seek first before you ask."); – yonan2236 Oct 12 '10 at 08:19
0
In your code when filling the list, check how many items there are, and if it is only one, manually call the method that the selected index changed event is hooked up to.

cjk
- 45,739
- 9
- 81
- 112
-
-
If there is only one option and it is preselected, then it can make the user experience much more streamlined if the next action has already happened. – cjk Oct 12 '10 at 08:32
0
You want to call SelectedIndexChanged Event? I'm right?
If so, just do this:
private void callSelectedIndex()
{
ComboBox cb = new ComboBox(); // Some ComboBox control to pass.
comboBox1_SelectedIndexChanged(cb, null); // Your ComboBox's SelectedIndexChanged event method.
}

yonan2236
- 13,371
- 33
- 95
- 141