PDA

Click to See Complete Forum and Search --> : Uselecting DropDownList Item


jstansell
Dec 11th, 2003, 05:18 PM
This seems like a real easy question but I can not figure it out.

I have a DropDownList control that is bound to a dataset. This works fine, however, the DropDownList control automatically selects the first item in this list. How can I make the list start out without any item selected?

thanks

pvb
Dec 11th, 2003, 07:04 PM
Just need to insert a new item after you databind:
protected override void OnInit(System.EventArgs e)
{
if (!Page.IsPostBack)
{
...
...
YourDropDownList.DataBind();
YourDropDownList.Items.Insert(0, new ListItem("- Select -", "-1"));
}
}

MarkusJ_NZ
Dec 14th, 2003, 09:54 PM
Have you tried going

YourDropDownList.SelectedItemIndex = -1

Cheers
MarkusJ