drop down list - how to force selected item

Discussion in 'ASP .Net' started by Geary, Jul 20, 2007.

  1. Geary

    Geary Guest

    I have a drop down list on an asp.net 2 page that is bound to a table.
    By default it displays the first item as the selected item. But I want
    to make sure that the user must change the selection. I am using the
    change-selection event to trigger so other code. If the user is
    satisfied with the default this other code won't run. So I am adding an
    additional .item.add("(None)") after the .databind() to add a (None)
    selection to the list. The problem is that the (None) selection is at
    the bottom of the list. How do I force the (None) selection to be the
    initial selected item? Or is there a better way of doing this? If I
    put the .item.add before the .databind, the (None)item is overwritten
    with the bound data.
     
    Geary, Jul 20, 2007
    #1
    1. Advertising

  2. Hello Geary

    > The problem is that the (None) selection is at the bottom of the list.
    > How do I force the (None) selection to be the initial selected item? Or
    > is there a better way of doing this? If I put the .item.add before the
    > .databind, the (None)item is overwritten with the bound data.

    Set the Property "AppendDataBoundItems" to true.
    This ensures that the additional item wouldnt be overwritten by
    the databound data.

    example code to add an item:
    this.dropTest.Items.Add(new ListItem("---please choose---", "initial
    value"));

    --
    Gruss, Peter Bucher
    Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
    http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
    http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET
     
    Peter Bucher [MVP], Jul 20, 2007
    #2
    1. Advertising

  3. Geary

    Geary Guest

    It sounded right but still isn't doing what I need. I probably should
    have given fuller detail.

    I have 3 drop-down boxes kind of daisy-chained to together. The 1st is
    for the department. In its change_selected event, I read it's new value
    to determine what equipment list to load into the 2nd drop-down(equip).
    Then once the user selects the equipment in that drop-down, I want the
    3rd drop-down to display the models that run on the selected equipment.

    The departments are hard-coded in the 1st list. When I change the
    selected dept, the proper equipment appears in the 2nd list. But if the
    initial displayed equipment happens to be the one that the user wants,
    there is no change_selected event to trigger the loading the right model
    numbers into the 3rd list.

    When I tried the solution you sent. It appended the "please choose"
    item and the new table data to the existing items already on the list.
    I tried different arrangements of setting the .appendDataBoundItems back
    and forth from true to false, to clear and then load the items in the
    order I wanted, without success.

    I remember back in the VB4 days of being about to manipulate the list
    index to do things like this. I'm just not finding equivalent
    functionary with the new stuff.


    Peter Bucher [MVP] wrote:
    > Hello Geary
    >
    >> The problem is that the (None) selection is at the bottom of the list.
    >> How do I force the (None) selection to be the initial selected item? Or
    >> is there a better way of doing this? If I put the .item.add before the
    >> .databind, the (None)item is overwritten with the bound data.

    > Set the Property "AppendDataBoundItems" to true.
    > This ensures that the additional item wouldnt be overwritten by
    > the databound data.
    >
    > example code to add an item:
    > this.dropTest.Items.Add(new ListItem("---please choose---", "initial
    > value"));
    >
     
    Geary, Jul 20, 2007
    #3
  4. Geary

    Brandon Gano Guest

    DropDownList has an AppendDataBoundItems property that needs to be set to
    true. If you do that, you should be able to add the item before the databind
    and retain the order you're looking for.


    "Geary" <> wrote in message
    news:...
    > It sounded right but still isn't doing what I need. I probably should
    > have given fuller detail.
    >
    > I have 3 drop-down boxes kind of daisy-chained to together. The 1st is
    > for the department. In its change_selected event, I read it's new value
    > to determine what equipment list to load into the 2nd drop-down(equip).
    > Then once the user selects the equipment in that drop-down, I want the 3rd
    > drop-down to display the models that run on the selected equipment.
    >
    > The departments are hard-coded in the 1st list. When I change the
    > selected dept, the proper equipment appears in the 2nd list. But if the
    > initial displayed equipment happens to be the one that the user wants,
    > there is no change_selected event to trigger the loading the right model
    > numbers into the 3rd list.
    >
    > When I tried the solution you sent. It appended the "please choose" item
    > and the new table data to the existing items already on the list. I tried
    > different arrangements of setting the .appendDataBoundItems back and forth
    > from true to false, to clear and then load the items in the order I
    > wanted, without success.
    >
    > I remember back in the VB4 days of being about to manipulate the list
    > index to do things like this. I'm just not finding equivalent functionary
    > with the new stuff.
    >
    >
    > Peter Bucher [MVP] wrote:
    >> Hello Geary
    >>
    >>> The problem is that the (None) selection is at the bottom of the list.
    >>> How do I force the (None) selection to be the initial selected item? Or
    >>> is there a better way of doing this? If I put the .item.add before the
    >>> .databind, the (None)item is overwritten with the bound data.

    >> Set the Property "AppendDataBoundItems" to true.
    >> This ensures that the additional item wouldnt be overwritten by
    >> the databound data.
    >>
    >> example code to add an item:
    >> this.dropTest.Items.Add(new ListItem("---please choose---", "initial
    >> value"));
    >>
     
    Brandon Gano, Jul 21, 2007
    #4
    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. Marina
    Replies:
    6
    Views:
    13,591
    KROSS
    Jan 21, 2008
  2. =?Utf-8?B?TWVyZGFhZA==?=

    Drop down list does not see the selected item!

    =?Utf-8?B?TWVyZGFhZA==?=, Oct 20, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    11,867
    =?Utf-8?B?TWVyZGFhZA==?=
    Oct 20, 2004
  3. Stephen Adam
    Replies:
    3
    Views:
    12,119
    Stephen Adam
    Nov 30, 2004
  4. weiwei
    Replies:
    0
    Views:
    1,022
    weiwei
    Jan 5, 2007
  5. Replies:
    0
    Views:
    177
Loading...

Share This Page