This code describes how to fill dropdown using dataset
Consider a Dropdownlist ddlTest, table tblEmp with
2 columns say eno,ename
private void FillDropdown() { Try { string strQry =" select eno, ename from tblEmp";
Dataset ds = new DataSet(); da = new SqlDataAdapter(strQry , m_objConn); da.Fill(ds,"DATA_TABLE"); da.Dispose(); ddlTest.Items.clear(); ddlTest.DataValueField ="eno"; ddlTest.DataTextField ="ename"; ddlTest.DataSouce = ds.Tables["DATA_TABLE"]; ddlTest.DataBind() } catch(exception ex) { ex.Message.ToString(); } }
<b> using ddlTest.selectedItem.Text we can Get the selected ename using ddlTest.SelectedItem.Value we can get the selected eno </b>
|
No responses found. Be the first to respond and make money from revenue sharing program.
|