how to fill DropDownList from database in asp.net ?
and when i pick value from the DropDownList how to catch this event ?
Conn.Open();
SQL = "SELECT distinct city FROM MEN";
dsView = new DataSet();
adp = new SqlDataAdapter(SQL, Conn);
adp.Fill(dsView, "MEN");
adp.Dispose();
DropDownList1. ?????? (what do to ?)
thanks in advance
You set the DataSource, DataTextField and DataValueField and call DataBind() in order to populate the dropdownlist.
The datasource can be pretty much any IEnumerable and the text and value will be looked up with reflection.
The event you want to catch is the SelectedIndexChanged event - this will fire when you change the selection.
First take the details in a dataset then the following code will help you:
DropDownList1.DataSource = ds
DropDownList1.DataTextField = "emailid"
DropDownList1.DataValueField = "userid"
DropDownList1.DataBind()
DropDownList1.Items.Insert(0, New ListItem("select", "-1"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With