Asp.net - Add blank item at top of dropdownlist

Saif Khan picture Saif Khan · Nov 6, 2008 · Viewed 236.7k times · Source

Why is the dropdown not showing my blank item first? Here is what I have

drpList.Items.Add(New ListItem("", ""))

With drpList
    .DataSource = myController.GetList(userid)
    .DataTextField = "Name"
    .DataValueField = "ID"
    .DataBind()
End With

Edit ~ I am binding to a Generig List, could this be the culprit?

Answer

JasonS picture JasonS · Nov 6, 2008

After your databind:

drpList.Items.Insert(0, new ListItem(String.Empty, String.Empty));
drpList.SelectedIndex = 0;