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????????
A:
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.
ck
2010-10-12 07:43:13
i dont want to manually call the function
Sheetal Inani
2010-10-12 07:49:57
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.
ck
2010-10-12 08:32:29
A:
Do as below check for the count of items and set the selectedindex property.
if (dcreportingto.Items.Count > 0)
{
dcreportingto.SelectedIndex = 0;
//call selected index change
}
Pranay Rana
2010-10-12 07:44:34
i want to call the selected index change method... but there is only one item in the list... so method is not getting called
Sheetal Inani
2010-10-12 08:03:34
@Sheetal - you can call selected index change event as suggested in answer
Pranay Rana
2010-10-12 08:12:39
+1
A:
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
Stefano
2010-10-12 07:46:26
i have to fill the dropdownlist on every submit... so by append data bound.. the same name is coming again and again
Sheetal Inani
2010-10-12 07:58:37
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
Stefano
2010-10-12 08:09:00
i think this post answer your question : http://stackoverflow.com/questions/267064/asp-net-add-blank-item-at-top-of-dropdownlist
Stefano
2010-10-12 08:19:01
A:
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
2010-10-12 08:12:13