adding data dynamically in dropdownlist?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ndhamecha
    New Member
    • Feb 2010
    • 10

    adding data dynamically in dropdownlist?

    hello frds..
    pls can you give me urgent reply how to add values dynamically in dropdownlist as im new in using asp.net with c#

    please ...thank u in advance.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Well there are two approaches to this.
    The first is add items to the DropDownList using the DropDownList's Items.Add(listI tem) method (or the DropDownList's Items.Add(Strin g) method).

    Or you could add the items to the DropDownList by binding it to a DataSource. To do this you would set the DropDownList.Da taSource property to a table or collection of Objects that contains the items for the DropDownList. Then you would specify which column or property should be used as the DataValueField and which column or property should be used for the DataTextField.

    These two methods are very different from each other and it will dictate how you manipulate the items in the list later (if you need to manipulate these items). For example, if you add items to the DropDownList by binding the it to a data source...and then later you want to remove an item from the list...you must remove the item by modifying the data source that the DropDownList is bound to. If you added the items to the DropDownList using the Items.Add method than you could use the Items.Remove method to remove the items later when you needed to. You cannot use the items.Remove method to remove items if you have bound your DropDownList to data source or else the items will just re-appear later....

    Anyways, you should research the topic because this is a very basic question.
    The MSDN Library is a great resource that is provided by Microsoft that contains articles and documentation on all of the .NET controls, concepts, and much much more. I recommend that you bookmark this page and use it as your primary source when developing any application using .NET technology.

    To get you started you should check out the article in the MSDN Library on the topic of the DropDownList Class. If you scroll down in that article you will find a whole bunch of "How To" walk through links that show you how to use this control.

    -Frinny

    Comment

    • ndhamecha
      New Member
      • Feb 2010
      • 10

      #3
      Originally posted by Frinavale
      Well there are two approaches to this.
      The first is add items to the DropDownList using the DropDownList's Items.Add(listI tem) method (or the DropDownList's Items.Add(Strin g) method).

      Or you could add the items to the DropDownList by binding it to a DataSource. To do this you would set the DropDownList.Da taSource property to a table or collection of Objects that contains the items for the DropDownList. Then you would specify which column or property should be used as the DataValueField and which column or property should be used for the DataTextField.

      These two methods are very different from each other and it will dictate how you manipulate the items in the list later (if you need to manipulate these items). For example, if you add items to the DropDownList by binding the it to a data source...and then later you want to remove an item from the list...you must remove the item by modifying the data source that the DropDownList is bound to. If you added the items to the DropDownList using the Items.Add method than you could use the Items.Remove method to remove the items later when you needed to. You cannot use the items.Remove method to remove items if you have bound your DropDownList to data source or else the items will just re-appear later....

      Anyways, you should research the topic because this is a very basic question.
      The MSDN Library is a great resource that is provided by Microsoft that contains articles and documentation on all of the .NET controls, concepts, and much much more. I recommend that you bookmark this page and use it as your primary source when developing any application using .NET technology.

      To get you started you should check out the article in the MSDN Library on the topic of the DropDownList Class. If you scroll down in that article you will find a whole bunch of "How To" walk through links that show you how to use this control.

      -Frinny
      thank u

      ndhamecha

      Comment

      Working...