DropDownList 局部刷新

前台:

                    <tr>
                        <td style="padding-left: 10px;">
                            <asp:DropDownList ID="DropDownList1" runat="server" Width="140px" DataTextField="typeName"
                                DataValueField="typeid" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1">
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <td style="padding-left: 10px;">
                            <asp:UpdatePanel ID="UpdatePanel1" runat="server" RenderMode="Inline" UpdateMode="Conditional">
                                <ContentTemplate>
                                    <asp:DropDownList ID="DropDownList2" runat="server" Height="23px" Width="140px" AutoPostBack="True"
                                        OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged1">
                                    </asp:DropDownList>
                                </ContentTemplate>
                                <Triggers>
                                    <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
                                </Triggers>
                            </asp:UpdatePanel>
                        </td>
                    </tr>
                    <tr>
                        <td style="padding-left: 10px;">
                            <asp:UpdatePanel ID="UpdatePanel2" runat="server" RenderMode="Inline" UpdateMode="Conditional">
                                <ContentTemplate>
                                    <asp:DropDownList ID="DropDownList3" runat="server" Height="23px" Width="140px">
                                    </asp:DropDownList>
                                </ContentTemplate>
                                <Triggers>
                                    <asp:AsyncPostBackTrigger ControlID="DropDownList2" EventName="SelectedIndexChanged" />
                                </Triggers>
                            </asp:UpdatePanel>
                        </td>
                    </tr>

 后台:

        private void bindfirst()
        {
            DataTable dt = typeinfo_BLL.GetList("t_typeid = 3").Tables[0];
            DropDownList1.DataSource = dt;
            DropDownList1.DataTextField = "typeName";
            DropDownList1.DataValueField = "typeid";
            DropDownList1.DataBind();
            DropDownList1.Items.Insert(0, new ListItem("--请选择类别--", "-1"));
            dt = null;
        }
        private void bindSecond(int id)
        {
            DataTable dt = typeinfo_BLL.GetList("t_typeid = " + id).Tables[0];
            DropDownList2.DataSource = dt;
            DropDownList2.DataTextField = "typeName";
            DropDownList2.DataValueField = "typeid";
            DropDownList2.DataBind();
            DropDownList2.Items.Insert(0, new ListItem("--请选择类别--", "-1"));
            dt = null;
        }
        private void bindThrid(int id)
        {
            DataTable dt = typeinfo_BLL.GetList("t_typeid = " + id).Tables[0];
            DropDownList3.DataSource = dt;
            DropDownList3.DataTextField = "typeName";
            DropDownList3.DataValueField = "typeid";
            DropDownList3.DataBind();
            DropDownList3.Items.Insert(0, new ListItem("--请选择类别--", "-1"));
            dt = null;
        }


        protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
        {
            DataTable dt = typeinfo_BLL.GetList("t_typeid = " + DropDownList1.SelectedValue).Tables[0];
            DropDownList2.DataSource = dt;
            DropDownList2.DataTextField = "typeName";
            DropDownList2.DataValueField = "typeid";
            DropDownList2.DataBind();
            bindSecond(Convert.ToInt32(DropDownList1.SelectedValue));
            dt = null;
        }

        protected void DropDownList2_SelectedIndexChanged1(object sender, EventArgs e)
        {
            DataTable dt = typeinfo_BLL.GetList("t_typeid = " + DropDownList2.SelectedValue).Tables[0];
            DropDownList3.DataSource = dt;
            DropDownList3.DataTextField = "typeName";
            DropDownList3.DataValueField = "typeid";
            DropDownList3.DataBind();
            bindThrid(Convert.ToInt32(DropDownList2.SelectedValue));
            dt = null;
        }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值