Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DropDownList - Selected Index To 0
Message
De
31/03/2010 09:11:37
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
 
À
31/03/2010 03:28:48
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01458151
Message ID:
01458188
Vues:
37
>>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....

This is the approach I always take.
Very fitting: http://xkcd.com/386/
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform