Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Asp.net C DropDownList筛选多个_C#_Asp.net_Webforms - Fatal编程技术网

C# Asp.net C DropDownList筛选多个

C# Asp.net C DropDownList筛选多个,c#,asp.net,webforms,C#,Asp.net,Webforms,因此,我有3个下拉框,我成功地使前两个起作用,这取决于第一个下拉框的选择学术,专业,但不起作用的是第三个下拉框,它没有显示需要插入的数据不确定我哪里出错了 protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e) { var value = DropDownList1.SelectedValue; DropDownList1.DataBind(); if (value

因此,我有3个下拉框,我成功地使前两个起作用,这取决于第一个下拉框的选择学术,专业,但不起作用的是第三个下拉框,它没有显示需要插入的数据不确定我哪里出错了

protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
{

    var value = DropDownList1.SelectedValue;
    DropDownList1.DataBind();

    if (value == "Professional")
    {
        DropDownList2.Items.Insert(0, new ListItem("Please Select One", string.Empty));
        DropDownList2.Items.Insert(1, new ListItem("Continuing - Professional", string.Empty));
        DropDownList2.Items.Insert(2, new ListItem("Fixed Term", string.Empty));
        DropDownList2.Items.Insert(3, new ListItem("Casual", string.Empty));
    }
    else if (value == "Academic")
    {
        DropDownList2.Items.Insert(0, new ListItem("Please Select One", string.Empty));
        DropDownList2.Items.Insert(1, new ListItem("Continuing - Academic", string.Empty));
        DropDownList2.Items.Insert(2, new ListItem("Fixed Term", string.Empty));
        DropDownList2.Items.Insert(3, new ListItem("Sessional", string.Empty));
    }
}

protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
    var value = DropDownList2.SelectedValue;
    DropDownList2.DataBind();

    if (value == "Continuing - Professional")
    {
        DropDownList5.Items.Insert(0, new ListItem("WORKED", string.Empty));

    }
    else if (value == "Fixed Term")
    {
        DropDownList5.Items.Insert(0, new ListItem("Worked, string.Empty));

    }
Aspx代码

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Staff.aspx.cs" Inherits="Staff" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        Staffing - Please Complete the Following</div>
        <asp:Label ID="Label1" runat="server" style="z-index: 1; left: 120px; top: 114px; position: absolute" Text="Position"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server" style="z-index: 1; left: 344px; top: 114px; position: absolute"></asp:TextBox>
        <asp:Label ID="Label2" runat="server" style="z-index: 1; left: 109px; top: 162px; position: absolute" Text="Fund Source"></asp:Label>
        <asp:TextBox ID="TextBox2" runat="server" style="z-index: 1; left: 343px; top: 161px; position: absolute" ReadOnly="True">University of Canberra</asp:TextBox>
        <asp:Label ID="Label3" runat="server" style="z-index: 1; left: 107px; top: 206px; position: absolute" Text="Emplyee Type"></asp:Label>
        <asp:Label ID="Label4" runat="server" style="z-index: 1; left: 102px; top: 248px; position: absolute" Text="Employment Basis"></asp:Label>
        <asp:DropDownList ID="DropDownList2" runat="server" style="z-index: 1; left: 342px; top: 248px; position: absolute; width: 127px" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
        </asp:DropDownList>
        <asp:Label ID="Label5" runat="server" style="z-index: 1; left: 126px; top: 291px; position: absolute" Text="Level"></asp:Label>
        <asp:Label ID="Label6" runat="server" style="z-index: 1; left: 126px; top: 333px; position: absolute" Text="Units"></asp:Label>
        <asp:DropDownList ID="DropDownList3" runat="server" style="z-index: 1; left: 342px; top: 334px; position: absolute; width: 128px">
            <asp:ListItem>Choose One</asp:ListItem>
            <asp:ListItem>FTE ( Continuing/Fixed-Term)</asp:ListItem>
            <asp:ListItem>Total Hours</asp:ListItem>
        </asp:DropDownList>
        <asp:Label ID="Label7" runat="server" style="z-index: 1; left: 96px; top: 375px; position: absolute" Text="Total Hours / FTE"></asp:Label>
        <asp:TextBox ID="TextBox4" runat="server" style="z-index: 1; left: 340px; top: 374px; position: absolute"></asp:TextBox>
        <asp:Label ID="Label8" runat="server" style="z-index: 1; left: 122px; top: 414px; position: absolute" Text="Start Date"></asp:Label>
        <asp:TextBox ID="TextBox5" runat="server" style="z-index: 1; left: 340px; top: 413px; position: absolute" TextMode="Date"></asp:TextBox>
        <asp:Label ID="Label9" runat="server" style="z-index: 1; left: 120px; top: 456px; position: absolute" Text="End Date"></asp:Label>
        <asp:TextBox ID="TextBox6" runat="server" style="z-index: 1; left: 338px; top: 451px; position: absolute" TextMode="Date"></asp:TextBox>
        <asp:Label ID="Label10" runat="server" style="z-index: 1; left: 118px; top: 498px; position: absolute" Text="Cost Basis"></asp:Label>
        <asp:DropDownList ID="DropDownList4" runat="server" style="z-index: 1; left: 336px; top: 497px; position: absolute; width: 128px">
            <asp:ListItem>Choose One</asp:ListItem>
            <asp:ListItem>Cost Recovery</asp:ListItem>
            <asp:ListItem>Cost Recovery + Grand Preperation</asp:ListItem>
            <asp:ListItem>Engagment Rate</asp:ListItem>
            <asp:ListItem>Government (State &amp; Fedral)</asp:ListItem>
            <asp:ListItem>Private Industry</asp:ListItem>
        </asp:DropDownList>
        <p>
        <asp:Button ID="Button1" runat="server" text="Back" OnClientClick="JavaScript:window.history.back(1);return false;" OnClick="Button1_Click1" style="z-index: 1; left: 361px; top: 565px; position: absolute"></asp:Button>
        </p>
        <asp:Button ID="Button2" runat="server" style="z-index: 1; left: 438px; top: 566px; position: absolute" Text="Save" OnClick="Button2_Click" />
        <asp:Button ID="Button3" runat="server" OnClick="Button3_Click" style="z-index: 1; left: 514px; top: 567px; position: absolute" Text="Next" />
        <asp:Label ID="Label11" runat="server" style="z-index: 1; left: 321px; top: 18px; position: absolute"></asp:Label>
        <asp:DropDownList ID="DropDownList5" runat="server" style="z-index: 1; left: 344px; top: 294px; position: absolute; width: 126px; height: 16px">
        </asp:DropDownList>
        <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1" style="z-index: 1; left: 345px; top: 209px; position: absolute; width: 126px">
            <asp:ListItem>Please Select One</asp:ListItem>
            <asp:ListItem>Professional</asp:ListItem>
            <asp:ListItem>Academic</asp:ListItem>
        </asp:DropDownList>
    </form>
</body>
</html>

您正在下拉列表2中添加项,该列表项的值为string.Empty,您是签入值,该值为空

试试下面的变化

受保护的void DropDownList1\u selectedIndexChanged1对象发送方,事件参数e {


你没有包括else if value==Casual或else if value==sessional哦,天哪,我正在尝试测试它是否有效,我会尝试添加所有其他条件,然后尝试。我会现在检查它,然后回复你好的,我试过了,所以没有完全相同的问题,代码读取dropsdownlist1并根据选择显示任何项目,但dropdownlist5根据中的选择拒绝显示项目dropdownlist2@DharyAlmousa它不起作用,因为您需要为DropDownList 2设置AutoPostBack=True,然后此处只触发SelectedIndexChanged事件。您还需要按照我的建议更改代码,但还有一件事,每次我更改选择时,列表都会堆积起来。如何才能我修正了你可以使用UpdatePanel进行部分回发,而不是整页回发。这不会从UI刷新页面
    var value = DropDownList1.SelectedValue;
    DropDownList1.DataBind();

    if (value == "Professional")
    {
        DropDownList2.Items.Insert(0, new ListItem("Please Select One", "Please Select One"));
        DropDownList2.Items.Insert(1, new ListItem("Continuing - Professional", "Continuing - Professional"));
        DropDownList2.Items.Insert(2, new ListItem("Fixed Term", "Fixed Term"));
        DropDownList2.Items.Insert(3, new ListItem("Casual", "Casual"));
    }
    else if (value == "Academic")
    {
        DropDownList2.Items.Insert(0, new ListItem("Please Select One", "Please Select One"));
        DropDownList2.Items.Insert(1, new ListItem("Continuing - Academic", "Continuing - Academic"));
        DropDownList2.Items.Insert(2, new ListItem("Fixed Term", "Fixed Term"));
        DropDownList2.Items.Insert(3, new ListItem("Sessional", "Sessional"));
    }
}