Adding a "None Selected" option to a DropDownList control that uses Databinding

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nathan Sokalski

    Adding a "None Selected" option to a DropDownList control that uses Databinding

    I have several DropDownList controls on my page that use databinding.
    However, I want to give users the option of selecting a choice such as "None
    Selected" or something else that shows they did not make a selection.
    However, if I attempt to add a ListItem to the Items collection when
    databinding is used it is removed and replaced by the item in the
    databinding source. Is there any simple way to add an extra ListItem, or do
    I have to build the collection using separate code? Thanks.
    --
    Nathan Sokalski
    njsokalski@hotm ail.com
    有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。



  • Brock Allen

    #2
    Re: Adding a "None Selected" option to a DropDownList control that uses Databinding

    DropDownList.It ems.Insert(0, "None Selected")

    -Brock
    DevelopMentor



    [color=blue]
    > I have several DropDownList controls on my page that use databinding.
    > However, I want to give users the option of selecting a choice such as
    > "None Selected" or something else that shows they did not make a
    > selection. However, if I attempt to add a ListItem to the Items
    > collection when databinding is used it is removed and replaced by the
    > item in the databinding source. Is there any simple way to add an
    > extra ListItem, or do I have to build the collection using separate
    > code? Thanks.
    >[/color]



    Comment

    • Jouni Karppinen

      #3
      Re: Adding a "None Selected" option to a DropDownList control that

      You can also use:
      DropDownList.It ems.Insert(0, new ListItem("-99", "None Selected"))

      This allows you to control also Value of new item also with Text. It might
      get handy when validating user input in postback.


      "Brock Allen" wrote:
      [color=blue]
      > DropDownList.It ems.Insert(0, "None Selected")
      >
      > -Brock
      > DevelopMentor
      > http://staff.develop.com/ballen
      >
      >
      >[color=green]
      > > I have several DropDownList controls on my page that use databinding.
      > > However, I want to give users the option of selecting a choice such as
      > > "None Selected" or something else that shows they did not make a
      > > selection. However, if I attempt to add a ListItem to the Items
      > > collection when databinding is used it is removed and replaced by the
      > > item in the databinding source. Is there any simple way to add an
      > > extra ListItem, or do I have to build the collection using separate
      > > code? Thanks.
      > >[/color]
      >
      >
      >
      >[/color]

      Comment

      Working...