AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 How can i enter Value into Dropdownlist
Posted by Venkata on  6/23/2009 8:57:36 AM Category: Asp.Net 2.0
Add to my favorites
Email to friend
Hi,

I need to enter Value into Dropdownlist(requirement is some cases i am populating values from data base some cases user needs to enter data manually) can any help on this issue.

Post Your Reply Post New Question

 Viewer's Reply
Solution: How can i enter Value into Dropdownlist
Answered By Moderator1 on 6/23/2009 10:26:52 AM
Hi,

You can dynamically add values to a dropdownlist with any of the following code.

Dropdownlist1.Items.Insert(0, new ListItem("Any Value", "Any Text"));

OR

Dropdownlist1.Items.Add(new ListItem("Any Value 1 ", "Any Text 1"));
 
binding values in dropdown from database
Answered By Salinee sachan on 6/24/2009 12:16:14 AM
i'm writong code i think it will be use ful

str = "select CustomerName,CustomerID from Customer"
da = New SqlDataAdapter(str, con)
ds = New DataSet
da.Fill(ds)
ddlCustomer.DataSource = ds
ddlCustomer.DataTextField = "CustomerName"
ddlCustomer.DataValueField = "CustomerID"
ddlCustomer.DataBind()
ddlCustomer.Items.Insert(0, "---Select Customer---")
ddlCustomer.Items(0).Value = 0
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
The JavaScript Anthology: 101 Essential Tips, Tricks & Hacks - Free 158 Page Preview
Oracle Magazine
The PHP Anthology: 101 Essential Tips, Tricks & Hacks, 2nd Edition - Free 207 Page Preview!