我有 3 个下拉菜单。当从第一个 ddl 中选择一个项目时,第二个 ddl 由相应的项目生成。选择第二个 ddl 时,第三个 ddl 生成各自的数据。我的问题是,当从第三个 ddl 中选择一个项目时,需要在网格视图中显示 3 个项目(1 个 ddl 的选定项目、2 个 ddl 的选定项目、3 个 ddl 的选定项目)。如何做到这一点?页面:
<body>
<form id="form1" runat="server">
<asp:DropDownList ID="DDLCountry" runat="server" OnSelectedIndexChanged="DDLCountry_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem>--Select-- </asp:ListItem>
<asp:ListItem>India</asp:ListItem>
<asp:ListItem>Australia</asp:ListItem>
<asp:ListItem>Pakistan</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DDLState" runat="server" OnSelectedIndexChanged="DDLState_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
<asp:DropDownList ID="DDLCity" runat="server" AutoPostBack="true"></asp:DropDownList>
<div>
<asp:GridView ID="Grd1" runat="server">
</asp:GridView>
</div>
</form>
aspx.cs 页面
protected void DDLCountry_SelectedIndexChanged(object sender, EventArgs e)
{
DDLCity.Items.Clear();
DDLState.Items.Clear();
if (DDLCountry.SelectedIndex == 1)
{
DDLState.Items.Add(new ListItem("select", "0"));
DDLState.Items.Add(new ListItem("Kerala", "1"));
DDLState.Items.Add(new ListItem("AP", "2"));
DDLState.Items.Add(new ListItem("Karnataka", "3"));
}
else if (DDLCountry.SelectedIndex == 2)
{
DDLState.Items.Add(new ListItem("select", "0"));
DDLState.Items.Add(new ListItem("Victoria", "1"));
DDLState.Items.Add(new ListItem("Western Australia", "2"));
DDLState.Items.Add(new ListItem("New South Wales", "3"));
}
else if (DDLCountry.SelectedIndex == 3)
{
DDLState.Items.Add(new ListItem("select", "0"));
DDLState.Items.Add(new ListItem("Balochstan", "1"));
DDLState.Items.Add(new ListItem("Sindh", "2"));
DDLState.Items.Add(new ListItem("Punjab", "3"));
}
}
protected void DDLState_SelectedIndexChanged(object sender, EventArgs e)
{
DDLCity.Items.Clear();
if ((DDLCountry.SelectedIndex == 1) && (DDLState.SelectedIndex == 1))
{
DDLCity.Items.Add(new ListItem("Calicut", "0"));
DDLCity.Items.Add(new ListItem("Kochi", "1"));
}
else if ((DDLCountry.SelectedIndex == 1) && (DDLState.SelectedIndex == 2))
{
DDLCity.Items.Add(new ListItem("Hyderabad", "0"));
DDLCity.Items.Add(new ListItem("Vijayawada", "1"));
}
else if ((DDLCountry.SelectedIndex == 1) && (DDLState.SelectedIndex == 3))
{
DDLCity.Items.Add(new ListItem("Bengaluru", "0"));
DDLCity.Items.Add(new ListItem("Mysore", "1"));
}
else if ((DDLCountry.SelectedIndex == 2) && (DDLState.SelectedIndex == 1))
{
DDLCity.Items.Add(new ListItem("Melbourne", "0"));
DDLCity.Items.Add(new ListItem("A", "1"));
}
else if ((DDLCountry.SelectedIndex == 2) && (DDLState.SelectedIndex == 2))
{
DDLCity.Items.Add(new ListItem("Perth", "0"));
DDLCity.Items.Add(new ListItem("B", "1"));
}
else if ((DDLCountry.SelectedIndex == 2) && (DDLState.SelectedIndex == 3))
{
DDLCity.Items.Add(new ListItem("Sydney", "0"));
DDLCity.Items.Add(new ListItem("C", "1"));
}
else if ((DDLCountry.SelectedIndex == 3) && (DDLState.SelectedIndex == 1))
{
DDLCity.Items.Add(new ListItem("Lahor", "0"));
DDLCity.Items.Add(new ListItem("D", "1"));
}
else if ((DDLCountry.SelectedIndex == 3) && (DDLState.SelectedIndex == 2))
{
DDLCity.Items.Add(new ListItem("Karachi", "0"));
DDLCity.Items.Add(new ListItem("E", "1"));
}
else if ((DDLCountry.SelectedIndex == 3) && (DDLState.SelectedIndex == 3))
{
DDLCity.Items.Add(new ListItem("Peshawar", "0"));
DDLCity.Items.Add(new ListItem("F", "1"));
}
}