三级联动

客户端:

<form id="form1" runat="server">

    <asp:ScriptManager ID="ScriptManager1" runat="server">

    </asp:ScriptManager>

    <div>

        <asp:UpdatePanel ID="UpdatePanel1" runat="server">

        <ContentTemplate>

            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"

                onselectedindexchanged="DropDownList1_SelectedIndexChanged">

            </asp:DropDownList>

            <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"

                onselectedindexchanged="DropDownList2_SelectedIndexChanged">

            </asp:DropDownList>

            <asp:DropDownList ID="DropDownList3" runat="server">

            </asp:DropDownList>

        </ContentTemplate>

        </asp:UpdatePanel>

    </div>

    </form>

 

服务端:

public partial class 三¨y级?联¢a动¡¥ : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        if (!IsPostBack)

        {

            DropDownList1.DataSource = ElectronMaster.DBHelper.GetTable("select * from T_System_Province");

            DropDownList1.DataTextField = "ProvinceName";

            DropDownList1.DataValueField = "ProvinceId";

            DropDownList1.DataBind();

 

            DropDownList1.Items.Insert(0,new ListItem("***请选择***"));

 

        }

    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)

    {

        DropDownList2.DataSource = ElectronMaster.DBHelper.GetTable("select * from T_System_City where ProvinceId=" + DropDownList1.SelectedItem.Value+ "");

        DropDownList2.DataTextField = "CityName";

        DropDownList2.DataValueField = "CityId";

        DropDownList2.DataBind();

 

        DropDownList2.Items.Insert(0, new ListItem("***请选择***"));

    }

    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)

    {

        DropDownList3.DataSource = ElectronMaster.DBHelper.GetTable("select * from T_System_Area where CityId=" + DropDownList2.SelectedItem.Value + "");

        DropDownList3.DataTextField = "AreaName";

        DropDownList3.DataValueField = "AreaId";

        DropDownList3.DataBind();

 

        DropDownList3.Items.Insert(0, new ListItem("***请选择***"));

    }

}

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值