Results 1 to 5 of 5

Thread: [RESOLVED] Setting asp:dropdownlist to ""

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Resolved [RESOLVED] Setting asp:dropdownlist to ""

    I have an aspropDownList control on one of my forms. When the page loads it contains the 1st value in the list. I know in VB.Net you can set the "SelectedIndex" property to -1 which leaves the control empty upon load. However, I tried doing that with the asp control and it didn't work. How is it done in ASP.Net?

    Thanks,
    Blake

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Setting asp:dropdownlist to ""

    Hey,

    Are you binding the DropDownList with Data from somewhere else?

    If so, on the DataBound event of the DropDownList, add some code to add another blank entry to the DropDownList.

    Something like:

    Code:
    DropDownList.Items.Insert(0, "")
    Gary

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Setting asp:dropdownlist to ""

    In web development, a dropdownlist (a select control) must have an item selected and so the browser defaults to the first if you don't select something yourself. Most devs get around this by introducing a "Please select one" item or a blank item.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Setting asp:dropdownlist to ""

    Gary,

    I added that code in the DAtabound Event and that worked. Mendhak, the field in question is a 2 digit state code, therefore somekind of message would not look right.

    Thanks guys,
    Blake

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] Setting asp:dropdownlist to ""

    Hey,

    Glad to hear you got it working!

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width