Archive

Posts Tagged ‘DropDownList’

Fill DropDownLists

Thursday, 24 April, 2008 Leave a comment

void FillDropDownLists()
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ASPGConnectionString"].ConnectionString);
SqlCommand commGetDept = new SqlCommand("select id, dept from s_dept where id in (select dept from s_users) order by dept", conn);
try
{
conn.Open();
SqlDataReader res = commGetDept.ExecuteReader();
ListDepts.DataTextField = "dept";
ListDepts.DataValueField = "id";
ListDepts.DataSource = res;
ListDepts.DataBind();
ListDepts.Items.Insert(0, "Все");
res.Close();
}
catch (SqlException sqlex)
{
//ErrMess.Text = sqlex.Message;
return;
}
catch
{
return;
}
finally
{
if (conn.State != ConnectionState.Closed) conn.Close();
}
}