Home > ASP.NET 2.0, C# > Fill DropDownLists

Fill DropDownLists

Thursday, 24 April, 2008 Leave a comment Go to comments

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();
}
}

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: