Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
hi how to binddata to a dropdown list in aspx page from sql?
Posted

First fill the dataset using dataadapter
SQL
dropdown.DataTextField="column to display";
dropdown.DataValueField="column to insert to DB";
 
Share this answer
 
Comments
Tech Code Freak 8-Feb-12 12:41pm    
5up!
Try this
C#
connection.Open();
SqlCommand cmd="Select * from table";
cmd.Connection=connection;
dropdown.DataSource=cmd.ExecuteReader();
dropdown.DataTextField="column to display";
dropdown.DataValueField="column to insert to DB";
dropdown.DataBind();
 
Share this answer
 
Comments
ythisbug 8-Feb-12 6:02am    
actually i dont want to insert to db..i want to retreive that in aspx page in drop down list??den wat u mean column to insert to db"??
Syed Salman Raza Zaidi 8-Feb-12 6:26am    
for eg if you have two columns ID and Name and you want to display name on aspx page and id to insert to DB then datavalue field will be ID, since you dont want to insert any value to DB,therefore you can give any column name from query as DataValuefield ;)
ythisbug 8-Feb-12 6:39am    
means in my db table contains column UserName and column Role[true/fasle]..and i want to display username where role is false...
Syed Salman Raza Zaidi 8-Feb-12 6:41am    
then your query should be select * from table where role=false, and you can give DataValuefield ="username";
ythisbug 8-Feb-12 7:09am    
ok thanks

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