Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DropDownList - Selected Index To 0
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01458151
Message ID:
01458235
Views:
33
>>>I have a DropDownList on my page. Loading it like this:
>>>
>>>
>>>cboProgramManager.DataSource = dsProgMgr.Tables[0];
>>>cboProgramManager.DataTextField = "Program Manager";
>>>cboProgramManager.DataValueField = "Program Manager";
>>>cboProgramManager.DataBind();
>>>cboProgramManager.SelectedIndex = -1;
>>>
>>>
>>>When I run it the first item in the list is selected. I don't want any item selected by default.
>>
>>From help:
>>Use the SelectedIndex property to programmatically specify or determine the index of the selected item from the DropDownList control. An item is always selected in the DropDownList control.
>>(my emphasis)
>>One solution is to add a dummy entry at the top:
cboProgramManager.DataBind();
>>cboProgramManager.Items.Insert(0,new ListItem("Select...."));
so that a SelectedIndex of 0 means nothing chosen....
>
>In any collection 0 is the first item, so I'm not so sure about that.
What aren't you sure about ?

>If that's true then it's entierely inconsistant with WinForms because in WinForms setting SelectedIndex to 0 elects the first item. To show no item selected you set SelectedIndex to -1;

WinForms doesn't have a DropdownList. Are you thinking of ComboBox ? Even so I don't think you can use -1.
From WinForms ComboBox.SelectedItem help:
"To deselect the currently selected item, set the SelectedIndex to -1. You cannot set the SelectedIndex of a ComboBox item to -1 if the item is a data-bound item"
Previous
Reply
Map
View

Click here to load this message in the networking platform