DropDownList二级无刷新功能实现

DropDownList二级无刷新功能实现


<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" >
    <Triggers>
        <!--注意这里是SelectedIndexChanged 不是OnSelectedIndexChanged事件名-->
        <asp:AsyncPostBackTrigger ControlID="sclassbig" EventName="SelectedIndexChanged" />
    </Triggers>
    <ContentTemplate>
    
    <asp:DropDownList ID="sclassbig" AutoPostBack="true" OnSelectedIndexChanged="select_change"
        runat="server">
        <asp:ListItem>保洁</asp:ListItem>
        <asp:ListItem>钟点工</asp:ListItem>
    </asp:DropDownList>
    
    <asp:DropDownList ID="sclasssml" AutoPostBack="true" runat="server">
    </asp:DropDownList>
    
    </ContentTemplate>
</asp:UpdatePanel>


cs 代码

 /// <summary>
    /// 绑定服务小类
    /// </summary>
    protected void smlbd()
    {
        string bigStr = "保洁";//默认服务选项
        DataTable dt = getSql("select sclasssml from sclass where sclassbig='"+bigStr+"'");
        sclasssml.DataSource = dt;
        sclasssml.DataTextField = "sclasssml";
        sclasssml.DataValueField = "sclasssml";
        sclasssml.DataBind();
    }
    /// <summary>
    /// 大类联动小类
    /// </summary>
    protected void select_change(object sender, EventArgs e)
    {
        string bigStr = sclassbig.SelectedValue;
        DataTable dt = getSql("select sclasssml from sclass where sclassbig='" + bigStr + "'");
        sclasssml.DataSource = dt;
        sclasssml.DataTextField = "sclasssml";
        sclasssml.DataValueField = "sclasssml";
        sclasssml.DataBind();
        //sclasssml.Items.Insert(0, "--请选择--");
        //sclasssml.Items[0].Value = "0";

    }


你可能感兴趣的:(asp.net)