473,434 Members | 3,225 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

adding data dynamically in dropdownlist?

ndhamecha
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.
Apr 21 '10 #1

✓ answered by Frinavale

Well there are two approaches to this.
The first is add items to the DropDownList using the DropDownList's Items.Add(listItem) method (or the DropDownList's Items.Add(String) method).

Or you could add the items to the DropDownList by binding it to a DataSource. To do this you would set the DropDownList.DataSource 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

2 4009
Frinavale
9,735 Expert Mod 8TB
Well there are two approaches to this.
The first is add items to the DropDownList using the DropDownList's Items.Add(listItem) method (or the DropDownList's Items.Add(String) method).

Or you could add the items to the DropDownList by binding it to a DataSource. To do this you would set the DropDownList.DataSource 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
Apr 21 '10 #2
@Frinavale
thank u

ndhamecha
Apr 22 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
4
by: theo | last post by:
Program flow...load file,then extract the xml text tags from the file,then the number of Xml tags retrieved from the file determines the number of dropdownlist controls instanciated in the...
2
by: Shiju Poyilil | last post by:
Hi ! I have a requirement wherein i am binding a datalist which contains a label (Caption for the field) and some literal hidden fields and a dropdown list. When I am binding to the datalist.....
0
by: Sileesh | last post by:
Hi I have html table and a Button in an Aspx page. I am adding one row with some textboxes to Html table each time i click on the Button thru Javascript. Now problem is when when i try to...
2
by: Dave | last post by:
Hi, I'm building a maintenance form for a table and some of the fields are textboxes (i.e name) and some should be dropdowns (i.e country of origin) When a user clicks 'Edit' in the...
5
by: Mike | last post by:
In ASP.NET 2.0 I have a dropdownlist populated from a sqldatasource. The dropdownlist values are successfully populated from a database table. I would like to add the value "Select Company" which...
3
by: Mark Denardo | last post by:
I'm trying to dynamically create and add controls to a web page: Label obj1 = new Label(); DropDownList obj2 = new DropDownList(); Controls.Add(obj1); Controls.Add(obj2); But I get the...
1
by: =?Utf-8?B?Z29yaWxsYQ==?= | last post by:
As we know , the view state is not responsible for having TextBoxes, CheckBoxes, DropDownLists, and other Web controls remember their values across postback. When I dynamically add a...
2
by: laxmibokka | last post by:
adding controls dynamically In my asp.net application, i have to add dropdownlist(with yes/no options), and textbox to the table cells dynamically to each row of a table.The table also contains some...
2
by: mylog | last post by:
Hi I am having a problem of getting the value from the dynamically generated table and dropdownlist. What I am facing is, I have created a table in the aspx page and now I need to add values to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.