Click here to Skip to main content
15,917,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to get the values from dropdown coming from database to dropdown
Posted
Comments
Sandeep Mewara 9-May-12 8:20am    
Did you try anything? What is the issue?

use sqlsource or using coding..


this is by coding.

C#
DataSet ds = new DataSet();
SqlDataAdapter myda = new SqlDataAdapter("select query",connection object );
myda.Fill(ds);
dropdown_name.DataSource = ds;
dropdown_name.DataValueField = "one field from select query";
dropdown_name.DataBind();
dropdown_name.Items.Insert(0, new ListItem("Select", "0"));
 
Share this answer
 
v3
Try this: here ddl1 is dropdownlist and con is ur connection string to database 

C#
con.Open();
SqlCommand cmd = new SqlCommand("select e_id, e_name from emp", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
DataSet ds = new DataSet();
da.Fill(ds);
dt = ds.Tables[0];
ddl1.DataValueField = dt.Columns[0].ToString();
ddl1.DataTextField = dt.Columns[1].ToString();
ddl1.DataSource = dt;
ddl1.DataBind();
ddl1.Items.Insert(0, "--SELECT--");
con.Close();
 
Share this answer
 
v2

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