How do you set DataBound Dropdownlist to "Choose"?

Discussion in 'ASP .Net' started by GS, Feb 14, 2006.

  1. GS

    GS Guest

    Hi,

    I have dropdown list bound to a Table, I don't want dropdown list to select first row from a table but rather to display "Choose" and when user clicks it then to display available values.
    How can I do that?
    GS, Feb 14, 2006
    #1
    1. Advertising

  2. GS

    tdavisjr Guest

    If using asp.net 2.0, the listbox has a property called
    AppendDataBoundItems, set that property to true. You then go ahead and
    use the designer to add a Choose to the listbox. After the databind
    you should still see Choose first.

    For 1.1, after to databind the items in the listbox in code you then
    just add a new listitem to the dropdown in code as well.
    tdavisjr, Feb 14, 2006
    #2
    1. Advertising

  3. GS,
    The easiest and least error-prone way is to add a row to the DataTable
    before databinding "Please Choose" with the InsertAt method, then bind to the
    control.
    Peter

    --
    Co-founder, Eggheadcafe.com developer portal:
    http://www.eggheadcafe.com
    UnBlog:
    http://petesbloggerama.blogspot.com




    "GS" wrote:

    > Hi,
    >
    > I have dropdown list bound to a Table, I don't want dropdown list to select first row from a table but rather to display "Choose" and when user clicks it then to display available values.
    > How can I do that?
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Feb 14, 2006
    #3
  4. GS

    GS Guest

    Excellent that's what I needed (I use ASP.NET 2.0).
    Now comes second problem since I bound GridView to DropDownList control and
    it errors out now becouse DropDownList contains invalid data (manual input).
    "tdavisjr" <> wrote in message
    news:...
    > If using asp.net 2.0, the listbox has a property called
    > AppendDataBoundItems, set that property to true. You then go ahead and
    > use the designer to add a Choose to the listbox. After the databind
    > you should still see Choose first.
    >
    > For 1.1, after to databind the items in the listbox in code you then
    > just add a new listitem to the dropdown in code as well.
    >
    GS, Feb 14, 2006
    #4
  5. GS

    tdavisjr Guest

    Reconfigure your datasource parameters. You should be able to set a
    default value for the parameter field in which you are telling it to
    get its value from a control on the page, which is the dropdown. So, a
    default value would be a valid dropdownlist value.

    This is all I can think of from the top of my head.
    tdavisjr, Feb 14, 2006
    #5
  6. Another way to add a default option to a dynamicly filled drop down is
    to use;

    mydropdown.Items.Insert(0,New ListItem("Choose...","none"))

    add that after you bind it to the data source.

    I ran into this issue earlier today and this worked for me. And similar
    to 'GS' I was then stuck with another drop down that was auto populated
    from the selection of the first drop down. But now that the
    ..SelectedValue was "none" it obviously didn't work. So what I created
    was prior to the 1st drop down being selected the 2nd dropdown.Enabled
    = False

    Then I have a onchange event on the 1st DD that enables the 2nd DD and
    runs the script to populate it on the postback based on the
    ..SelectedValue of the 1st DD.

    Works like a charm. Hope that made sense.

    Jeremy Reid
    http://blackstaronline.net
    blackstaronline.net, Feb 15, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rodchar
    Replies:
    0
    Views:
    384
    rodchar
    Nov 26, 2007
  2. Cirene

    "choose one" in a dropdownlist

    Cirene, Jun 4, 2008, in forum: ASP .Net
    Replies:
    3
    Views:
    454
    Cirene
    Jun 4, 2008
  3. Deep_Feelings
    Replies:
    12
    Views:
    482
    Paul Moore
    Jul 15, 2009
  4. Manu
    Replies:
    0
    Views:
    161
  5. Lagrange
    Replies:
    1
    Views:
    545
    Lagrange
    Jan 17, 2009
Loading...

Share This Page