关于dropdownlist控件后台代码整合
以下是我的代码哦,我总感觉重复性好多,希望大家能帮我把代码整合下,我也好参考学习一下哦
string strCon = ConfigurationManager.AppSettings["MsSql"];
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindUserList();
ddlGroupIDBind();
ddlU_CNameBind();
ddlUserIDBind();
}
}
//部门下拉框
protected void ddlGroupIDBind()
{
string sqlSel = "select GroupID,G_CName from sys_Group where G_ParentID !=0 order by GroupID ";
SqlConnection con = new SqlConnection(strCon); ;
con.Open();
SqlDataAdapter sda = new SqlDataAdapter(sqlSel, con);
DataSet ds = new DataSet();
sda.Fill(ds);
ddlGroupID.DataSource = ds.Tables[0].DefaultView;
ddlGroupID.DataTextField = "G_CName";
ddlGroupID.DataValueField = "GroupID";
ddlGroupID.DataBind();
}
//员工姓名下拉框
protected void ddlU_CNameBind()
{
string sqlSel = "select UserID,U_CName from sys_User where U_GroupID='" + ddlGroupID.SelectedValue + "' order by UserID ";