ASP DROPDOWN 三级联动最好用

      <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">
                            </asp:ScriptManager>
                            <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                                <ContentTemplate>
                                    <asp:DropDownList ID="dpSheng" runat="server" Width="120px"
                                        AutoPostBack="true" OnSelectedIndexChanged="dpProvince_SelectedIndexChanged" />
                                    <asp:DropDownList ID="dpShi" runat="server" AutoPostBack="true" Width="120px"
                                        OnSelectedIndexChanged="dpCity_SelectedIndexChanged" />
                                    <asp:DropDownList ID="dpXian" runat="server" AutoPostBack="false" Width="120px"/>
                                    <asp:UpdateProgress ID="UpdateProgress1" runat="server">
                                        <ProgressTemplate>
                                            正在加载...
                                        </ProgressTemplate>
                                    </asp:UpdateProgress>
                                </ContentTemplate>
                                <%-- 异步回送防止整页刷新 --%>
                                <Triggers>
                                    <asp:AsyncPostBackTrigger ControlID="dpSheng" EventName="SelectedIndexChanged" />
                                    <asp:AsyncPostBackTrigger ControlID="dpShi" EventName="SelectedIndexChanged" />
                                </Triggers>
                            </asp:UpdatePanel>
 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindSheng();
            BindShi();
            BindXian();
        }
    }

    private void BindSheng()
    {
//获取省数据 dpSheng.DataSource
= baseParameterBll.GetModelDataList("par_type=0 and par_parent='0'"); dpSheng.DataValueField = "par_id"; dpSheng.DataTextField = "par_name"; dpSheng.DataBind(); dpSheng.Items.Insert(0, new ListItem("选择省份", "-")); } private void BindShi() { string sheng = dpSheng.SelectedValue; if (sheng != "-") { dpShi.DataSource = baseParameterBll.GetModelDataList("par_type=0 and par_parent='" + sheng + "'"); dpShi.DataValueField = "par_id"; dpShi.DataTextField = "par_name"; dpShi.DataBind(); } dpShi.Items.Insert(0, new ListItem("选择市", "-")); } private void BindXian() { string shi = dpShi.SelectedValue; if (shi != "-") { dpXian.DataSource = baseParameterBll.GetModelDataList("par_type=0 and par_parent='" + shi + "'"); dpXian.DataValueField = "par_id"; dpXian.DataTextField = "par_name"; dpXian.DataBind(); } dpXian.Items.Insert(0, new ListItem("选择区", "-")); } protected void dpProvince_SelectedIndexChanged(object sender, EventArgs e) { dpShi.Items.Clear(); BindShi(); dpXian.Items.Clear(); BindXian(); } protected void dpCity_SelectedIndexChanged(object sender, EventArgs e) { dpXian.Items.Clear(); BindXian(); } } }

 

posted @ 2019-03-28 09:43  JaneAi  阅读(471)  评论(0编辑  收藏  举报