.NET ----- 多级联动

 联动

<tr>
<td width="20%" align="right" bgcolor="#F5F5F5">报考地区:</td>
<td align="left" bgcolor="#FFFFFF" width="30%">
<asp:DropDownList ID="ddlXueLi_Area_4501_Code" runat="server" width="121px" AutoPostBack="true" OnSelectedIndexChanged="ddlXueLi_Area_4501_Code_SelectedIndexChanged"></asp:DropDownList></td>

<td width="20%" align="right" bgcolor="#F5F5F5">报考层次:</td>
<td align="left" bgcolor="#FFFFFF" width="30%">
<asp:DropDownList ID="ddlXueLi_CengCi_4501_Code" runat="server" width="121px" AutoPostBack="true" OnSelectedIndexChanged="ddlXueLi_Area_4501_Code_SelectedIndexChanged"></asp:DropDownList></td>
</tr>

<tr>
<td width="20%" align="right" bgcolor="#F5F5F5">报考学校:</td>
<td align="left" bgcolor="#FFFFFF" width="30%">
<asp:DropDownList ID="ddlXueLi_School_4501_Code" runat="server" width="121px" AutoPostBack="true" OnSelectedIndexChanged="ddlXueLi_Area_4501_Code_SelectedIndexChanged"></asp:DropDownList></td>

<td width="20%" align="right" bgcolor="#F5F5F5">报考专业:</td>
<td align="left" bgcolor="#FFFFFF" width="30%">
<asp:DropDownList ID="ddlXueLi_ZhuanYe_4501_Code" runat="server" width="121px" AutoPostBack="true" OnSelectedIndexChanged="ddlXueLi_Area_4501_Code_SelectedIndexChanged"></asp:DropDownList></td>

</tr>

获取第一级的,然后通过前面的 函数调用后面的方法

    {//报考地区
            List<ITEM.Model.qdCnt4.FourCollsType> mList = _bllTypeColls.Get_Ex_FourCollsTypeListByIDLevel("TypeCollCode,TypeCollName", base.EnterpriseGuid, 4501, 1, (float)_iFlag);
            this.ddlXueLi_Area_4501_Code.DataTextField = "TypeCollName";
            this.ddlXueLi_Area_4501_Code.DataValueField = "TypeCollCode";
            this.ddlXueLi_Area_4501_Code.DataSource = mList;
            this.ddlXueLi_Area_4501_Code.DataBind();
            this.ddlXueLi_Area_4501_Code.Items.Insert(0, new ListItem());
        }

方法

 protected void ddlXueLi_Area_4501_Code_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)sender;
        if (ddl.ID == "ddlXueLi_Area_4501_Code")
        {
            string sCode = this.ddlXueLi_Area_4501_Code.SelectedValue;
            if (sCode != string.Empty)
            {
                List<ITEM.Model.qdCnt4.FourCollsType> mList = _bllTypeColls.Get_Ex_FourCollsTypeList_CodeDown("TypeCollCode,TypeCollName", base.EnterpriseGuid, 4501, sCode, 2, (float)_iFlag);
                this.ddlXueLi_CengCi_4501_Code.DataTextField = "TypeCollName";
                this.ddlXueLi_CengCi_4501_Code.DataValueField = "TypeCollCode";
                this.ddlXueLi_CengCi_4501_Code.DataSource = mList;
                this.ddlXueLi_CengCi_4501_Code.DataBind();
                this.ddlXueLi_CengCi_4501_Code.Items.Insert(0, new ListItem());
            }
        }
        else if (ddl.ID == "ddlXueLi_CengCi_4501_Code")
        {
            string sCode = this.ddlXueLi_CengCi_4501_Code.SelectedValue;
            if (sCode != string.Empty)
            {
                List<ITEM.Model.qdCnt4.FourCollsType> mList = _bllTypeColls.Get_Ex_FourCollsTypeList_CodeDown("TypeCollCode,TypeCollName", base.EnterpriseGuid, 4501, sCode, 3, (float)_iFlag);
                this.ddlXueLi_School_4501_Code.DataTextField = "TypeCollName";
                this.ddlXueLi_School_4501_Code.DataValueField = "TypeCollCode";
                this.ddlXueLi_School_4501_Code.DataSource = mList;
                this.ddlXueLi_School_4501_Code.DataBind();
                this.ddlXueLi_School_4501_Code.Items.Insert(0, new ListItem());
            }
        }
        else if (ddl.ID == "ddlXueLi_School_4501_Code")
        {
            string sCode = this.ddlXueLi_School_4501_Code.SelectedValue;
            if (sCode != string.Empty)
            {
                List<ITEM.Model.qdCnt4.FourCollsType> mList = _bllTypeColls.Get_Ex_FourCollsTypeList_CodeDown("TypeCollCode,TypeCollName", base.EnterpriseGuid, 4501, sCode, 4, (float)_iFlag);
                this.ddlXueLi_ZhuanYe_4501_Code.DataTextField = "TypeCollName";
                this.ddlXueLi_ZhuanYe_4501_Code.DataValueField = "TypeCollCode";
                this.ddlXueLi_ZhuanYe_4501_Code.DataSource = mList;
                this.ddlXueLi_ZhuanYe_4501_Code.DataBind();
                this.ddlXueLi_ZhuanYe_4501_Code.Items.Insert(0, new ListItem());
            }
        }
        else if (ddl.ID == "ddlXueLi_ZhuanYe_4501_Code")
        {
            string sCode = this.ddlXueLi_ZhuanYe_4501_Code.SelectedValue;
            if (sCode != string.Empty)
            {
                ITEM.Model.qdCnt4.FourCollsType m = _bllTypeColls.Get_Ex_Model_FourCollsTypeListByCollCode("TypeCollCode,TypeCollName", base.EnterpriseGuid, 4501, sCode, (float)_iFlag);
                this.tbPrice_zhidao.Text = m.Ext01;
            }
        }
    }

保存的时候赋值

   gbaoming_xueli.XueLi_Area_4501_Code = this.ddlXueLi_Area_4501_Code.SelectedValue;
        gbaoming_xueli.XueLi_Area_4501_Name = this.ddlXueLi_Area_4501_Code.SelectedItem.Text;
        gbaoming_xueli.XueLi_CengCi_4501_Code = this.ddlXueLi_CengCi_4501_Code.SelectedValue;
        gbaoming_xueli.XueLi_CengCi_4501_Name = this.ddlXueLi_CengCi_4501_Code.SelectedItem.Text;
        gbaoming_xueli.XueLi_School_4501_Code = this.ddlXueLi_School_4501_Code.SelectedValue;
        gbaoming_xueli.XueLi_School_4501_Name = this.ddlXueLi_School_4501_Code.SelectedItem.Text;
        gbaoming_xueli.XueLi_ZhuanYe_4501_Code = this.ddlXueLi_ZhuanYe_4501_Code.SelectedValue;
        gbaoming_xueli.XueLi_ZhuanYe_4501_Name = this.ddlXueLi_ZhuanYe_4501_Code.SelectedItem.Text;
        if (gbaoming_xueli.XueLi_Area_4501_Code == string.Empty)
        {
            WebMessageBox1.MessageBox_tishi(700, 300, 200, 300, "请选择报考地区");
            return;
        }
        if (gbaoming_xueli.XueLi_CengCi_4501_Code == string.Empty)
        {
            WebMessageBox1.MessageBox_tishi(700, 300, 200, 300, "请选择报考层次");
            return;
        }

        if (gbaoming_xueli.XueLi_School_4501_Code == string.Empty)
        {
            WebMessageBox1.MessageBox_tishi(700, 300, 200, 300, "请选择报考院校");
            return;
        }
        if (gbaoming_xueli.XueLi_ZhuanYe_4501_Code == string.Empty)
        {
            WebMessageBox1.MessageBox_tishi(700, 300, 200, 300, "请选择专业名称");
            return;
        }

 

修改展示使:

            this.ddlXueLi_Area_4501_Code.SelectedValue = gbaoming_xueli.XueLi_Area_4501_Code;
            ddlXueLi_Area_4501_Code_SelectedIndexChanged(this.ddlXueLi_Area_4501_Code, new EventArgs());

            this.ddlXueLi_CengCi_4501_Code.SelectedValue = gbaoming_xueli.XueLi_CengCi_4501_Code;
            ddlXueLi_Area_4501_Code_SelectedIndexChanged(this.ddlXueLi_CengCi_4501_Code, new EventArgs());

            this.ddlXueLi_School_4501_Code.SelectedValue = gbaoming_xueli.XueLi_School_4501_Code;
            ddlXueLi_Area_4501_Code_SelectedIndexChanged(this.ddlXueLi_School_4501_Code, new EventArgs());

            this.ddlXueLi_ZhuanYe_4501_Code.SelectedValue = gbaoming_xueli.XueLi_ZhuanYe_4501_Code;
            ddlXueLi_Area_4501_Code_SelectedIndexChanged(this.ddlXueLi_ZhuanYe_4501_Code, new EventArgs());

还有个

            this.ddlXueLi_Area_4501_Code.Enabled = false;
            this.ddlXueLi_Area_4501_Code.Attributes.Add("style", "color:#888888;");//所属省

            this.ddlXueLi_CengCi_4501_Code.Enabled = false;
            this.ddlXueLi_CengCi_4501_Code.Attributes.Add("style", "color:#888888;");//报考层次

            this.ddlXueLi_School_4501_Code.Enabled = false;
            this.ddlXueLi_School_4501_Code.Attributes.Add("style", "color:#888888;");//报考层次

            this.ddlXueLi_ZhuanYe_4501_Code.Enabled = false;
            this.ddlXueLi_ZhuanYe_4501_Code.Attributes.Add("style", "color:#888888;");//报考层次

 

使用会掉函数调用

 

posted on 2020-06-28 16:13  obge  阅读(223)  评论(0编辑  收藏  举报