猿问

如何实现联动?

我在页面上有2个dropdownlist控件,我希望另外一个dropdownlist的内容取决于另外一个的选择,  protected void ddpM_Type_SelectedIndexChanged(object sender, EventArgs e)

{

  string strWhere = "DelFlag = 'false'";
           if (this.ddpM_People.SelectedValue == "内部维修")
            {

                ddpM_Company.Items.Clear();
                ddpM_Company.DataTextField = "Dept_Name";
                ddpM_Company.DataValueField = "Dept_ID";
                bindList(ddpM_Company, department.GetList(strWhere).Tables[0]); 
              
            }
            if (this.ddpM_People.SelectedValue == "外委维修")
            {

                ddpM_Company.Items.Clear();
                ddpM_Company.DataTextField = "C_Name";
                ddpM_Company.DataValueField = "C_ID";
                bindList(ddpM_Company, corporations.GetList(strWhere).Tables[0]);
              
            }

}

但是这样没效果,我dropdownlist里面的内容是从数据库中读取的,请问如何实现联动啊?


森林海
浏览 559回答 3
3回答

蝴蝶刀刀

第一个DropDownList的AutoPostBack属性要设置true,然后在触发的相关事件中代码要绑定正确。这样就可以了
随时随地看视频慕课网APP
我要回答