Asp.net(C#)两个DropDownList联动。

利用DropDownList的DropDownList_BuName_SelectedIndexChanged事件。

注意红色部分,不写     AutoPostBack="True" ,事件不起作用的。


Asp页面上:

                           商户名称:
                            <asp:DropDownList ID="DropDownList_BuName" runat="server" Width='200px'
                                AutoPostBack="True"
                                onselectedindexchanged="DropDownList_BuName_SelectedIndexChanged">
                            </asp:DropDownList>
                            <asp:DropDownList ID="DropDownList_Pos" runat="server" DataValueField="PosNum"
                                DataTextField="PosNum">
                            </asp:DropDownList>


C#后台代码:

      

 #region 选择商户之后,加载POS编号列表
        protected void DropDownList_BuName_SelectedIndexChanged(object sender, EventArgs e)
        {
            string buName = DropDownList_BuName.SelectedItem.ToString();
            if (buName != "-全部-")
            {
                DropDownList_Pos.DataSource = null;
                //根据商户编号查询所有的POS编号
                string querySql = "select PosNum from Tbl_Pos where Bucode = '" + buName.Split('-')[0].ToString() + "'";
                DataSet posDs = DBFhkHelper.queryDB(querySql);
                DataTable table = posDs.Tables[0];

                DataTable table1 = new DataTable();
                table1.Columns.Add("PosNum");
                DataRow drNew = table1.NewRow();
                drNew["PosNum"] = "-不选择POS-";
                table1.Rows.Add(drNew);
                table1.Merge(table);

                DropDownList_Pos.DataSource = table1;
                DropDownList_Pos.DataBind();
            }
            else
            {
                DropDownList_Pos.DataSource = null;
                DropDownList_Pos.Items.Add("-不选择POS-");
                DropDownList_Pos.DataBind();
            }
        }
        #endregion 选择商户之后,加载POS编号列表


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值