Drop down lists
how to display the Table data of one column to the drop down list when selected.
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vishal GilbileRank #268 · 9.4K reputationPosted Mar 17, 2013, 6:59 PM EDT
Below is the code for the same. Assuming that your DB is SQl Server.
SqlConnection con=new SqlConnection("Your Connection String over here");
SqlDataAdapater da=new SqlDataAdapter("SQl Query",con);
DataSet ds=new DataSet();
da.Fill(ds,"TableName (optional)");
dropdownlist1.DataSource=ds.Tables[0].DefaultView;
drodownlist1.DataMember=dropdownlist1.DataValueField="Column Name"; //which to be used for selected value changed.
dropdownlist1.DataTextField="ColumnName";// which should appear as a Text.
dropdownlist1.DataBind()//in case your frontend is asp.net.
The above code will bind the your db column data to the dropdownlist.
With Regards,
Vishal Gilbile.