Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
How do i fill the dropdown of combobx from a db
Posted
Comments
_Amy 19-Oct-12 1:43am    
What have you tried yet? I searched with your subject in Google. See the link below:
Filling the dropdown item from the database[^]

Get the result from database
C#
//clsUser is my own defined class with the UserSelect method
clsUser objUsers = new clsUser();
DataTable dtUser = objUsers.UserSelect("Select * from Users");

//take a combobox in front end or in codebehind
ComboBox cmb = new ComboBox();
cmb.DropDownStyle = ComboBoxStyle.DropDownList;
//set the datasource 
cmb.DataSource = dtUser.Copy();
 
Share this answer
 
You should have at least googled for "fill combobox from database c#". There is even a youtube video showing how to do that:
http://www.youtube.com/watch?v=izlgxu51RoQ[^]
or read these forum posts:
http://www.dreamincode.net/forums/topic/145973-fill-data-from-database-in-the-combobox/[^]
http://forums.codeguru.com/showthread.php?472847-Populate-ComboBox-from-db-Select-RecordID[^]
 
Share this answer
 
Try this,

C#
DropDownList1.DataSource = dt;
       DropDownList1.DataTextField = "Name";
       DropDownList1.DataValueField = "ID";
       DropDownList1.DataBind();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900