日期:2014-05-17 浏览次数:20503 次
protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { startData(); } } //绑定初始数据 protected void startData() { DataSet ds = new DataSet(); UM.userName=Session["user"].ToString(); ds = UB.users_QueryUserDetail_by_Name(UM); ListItem myListItem0 = new ListItem("一棉", "firDepartmentName"); ListItem myListItem1 = new ListItem("二棉", "firDepartmentName"); string firDepartmentName = ds.Tables[0].Rows[0]["firDepartmentName"].ToString(); //一级部门 if (firDepartmentName=="一棉") { //移除所有的item DropDownList1.Items.Clear(); //这里把选择项“一棉”放在前面 this.DropDownList1.Items.Add(myListItem0); this.DropDownList1.Items.Add(myListItem1); } else { //移除所有的item DropDownList1.Items.Clear(); //这里把选择项“二棉”放在前面 this.DropDownList1.Items.Add(myListItem1); this.DropDownList1.Items.Add(myListItem0); } //二级部门 string secDepartmentName = ds.Tables[0].Rows[0]["secDepartmentName"].ToString(); DropDownList2.Items.Add(secDepartmentName); } //动态绑定二级部门数据 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { //清除DropDownList2原来的item DropDownList2.Items.Clear(); string FirDeparName = DropDownList1.SelectedItem.Text; DataSet ds = SDB.secDepartment_Query_by_FirDeparName_dataset(FirDeparName); DropDownList2.DataSource = ds; DropDownList2.DataValueField= "secDepartmentName";//绑定DropDownList2的DataValueField属性 DropDownList2.DataTextField = "secDepartmentName"; //绑定DropDownList2的DataTextField属性 DropDownList2.DataBind(); }