drop down lists
how to display the Table data of one column to the drop down list when selected.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Vishal GilbilePosted Mar 17, 2013, 10:59 PM
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.