How do i set the default value of a dropdownlist to nothing???

Hello,

 

I am workin with VB.Net doing a web application.  I fill the dropdownlist using datasets, but I want them not to have any selected value until the user selects one otherwise it should stay blank (with no selection).  Is ti possible to do that.

 

I used to do that in windows applications using setindex to -1 or something like that,

 

thanks for any suggestions.



Answer this question

How do i set the default value of a dropdownlist to nothing???

  • hosrow

    Thanx Imran. It was of greate help to me.

  • Anon56789

    You can add a blank item after you're done binding your dropdownlist. Something like this:

    With dd
      .DataTextField = "myText"
      .DataValueField = "myID"
      .DataSource = myDataSource
      .DataBind()
      'insert a blank item at the first position
      .Items.Insert(0, New ListItem("", "-1"))
    End With

    By default, the first item would be selected which is the blank item.

    hope that helps,
    Imran.

  • Ed M

    .Items.Insert(0, New ListItem("", "-1"))

    I found that the best place to put that line is in the Bound event of the DropDownList that you are inserting into.


  • How do i set the default value of a dropdownlist to nothing???