Monday, February 25, 2013

Binding the data to Dropdown list with Text field and Value Field:

1)Binding the data to Dropdown list with Text field and Value Field:

SqlConnection dbconn = new SqlConnection(Connection String);
dbconn.Open()
string query = "Select cmpname,ID from Compnies ORDER BY cmpname";
cmd = new SqlCommand(query, dbconn);
dr = cmd.ExecuteReader();
DrpList.DataSource = dr;
DrpList.DataValueField = "ID";
DrpList.DataTextField = "cmpname";
DrpList.DataBind();
dbconn.Close();

1 comment: