网页上有两个dropdownlist,当第一个框中选择人事局时,第二个框显示局长和副局长,当第一个框选择人事处时,第二个框显示处长和副处长,请问怎么弄

xiaozhuer000 2017-01-08 05:31:31
如题,想要实现联动,第二个框中数据随着第一个框选择的变化而变化,不知道怎么弄,请大牛们帮帮忙啊
...全文
241 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
WordG 2017-01-11
  • 打赏
  • 举报
回复
参照网上搜的三级联动 自己改下就行了
电饭锅煲汤 2017-01-09
  • 打赏
  • 举报
回复
在第一个下拉框绑定change事件
csdnFUCKINGSUCKS 2017-01-09
  • 打赏
  • 举报
回复
引用 4 楼 xiaozhuer000 的回复:
如果我要创建三级联动照着这个格式改,是吧
恩 基本就是这样 三级联动逻辑上要做一些修改 你自己试试应该能写出来
xiaozhuer000 2017-01-09
  • 打赏
  • 举报
回复
如果我要创建三级联动照着这个格式改,是吧
xiaozhuer000 2017-01-09
  • 打赏
  • 举报
回复
引用 1楼3ch0 的回复:
前台

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
        <asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList>
    </div>
    </form>
</body>
</html>
后台

namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DropDownList1.DataSource = GetList().Where(d => d.pid == 0);
                DropDownList1.DataValueField = "id";
                DropDownList1.DataTextField = "name";
                DropDownList1.DataBind();
            }
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            var result = GetList().Where(d => d.pid == int.Parse(DropDownList1.SelectedValue)).ToList();

            DropDownList2.DataSource = result;
            DropDownList2.DataValueField = "id";
            DropDownList2.DataTextField = "name";
            DropDownList2.DataBind();
        }

        private List<Department> GetList()
        {
            List<Department> list = new List<Department>();
            list.AddRange(new[] { 
                    new Department() { id = 1, pid = 0, name = "人事局" },
                    new Department() { id = 2, pid = 1, name = "局长" },
                    new Department() { id = 3, pid = 1, name = "副局长" },
                    new Department() { id = 4, pid = 0, name = "人事处" },
                    new Department() { id = 5, pid = 4, name = "处长" },
                    new Department() { id = 6, pid = 4, name = "副处长" }
                });
            return list;
        }
    }

    public class Department
    {
        public int id { get; set; }
        public int pid { get; set; }
        public string name { get; set; }
    }

}
谢谢,谢谢,我先试一试,
xujun5031 2017-01-09
  • 打赏
  • 举报
回复
下拉框联动。
csdnFUCKINGSUCKS 2017-01-08
  • 打赏
  • 举报
回复
前台

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
        <asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList>
    </div>
    </form>
</body>
</html>
后台

namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DropDownList1.DataSource = GetList().Where(d => d.pid == 0);
                DropDownList1.DataValueField = "id";
                DropDownList1.DataTextField = "name";
                DropDownList1.DataBind();
            }
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            var result = GetList().Where(d => d.pid == int.Parse(DropDownList1.SelectedValue)).ToList();

            DropDownList2.DataSource = result;
            DropDownList2.DataValueField = "id";
            DropDownList2.DataTextField = "name";
            DropDownList2.DataBind();
        }

        private List<Department> GetList()
        {
            List<Department> list = new List<Department>();
            list.AddRange(new[] { 
                    new Department() { id = 1, pid = 0, name = "人事局" },
                    new Department() { id = 2, pid = 1, name = "局长" },
                    new Department() { id = 3, pid = 1, name = "副局长" },
                    new Department() { id = 4, pid = 0, name = "人事处" },
                    new Department() { id = 5, pid = 4, name = "处长" },
                    new Department() { id = 6, pid = 4, name = "副处长" }
                });
            return list;
        }
    }

    public class Department
    {
        public int id { get; set; }
        public int pid { get; set; }
        public string name { get; set; }
    }

}

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧