问题描述
嗨亲爱的
我在更新面板中有3个下拉列表。
国家,州,地区。这3个下拉列表是相关的。
如果我从国家/地区下拉列表中选择国家/地区名称,则所选国家/地区的所有州都将在州下拉列表中可用。它只适用于第一次回发...
状态下拉列表并不令所有回发更新,除了第一次回发..
我使用了
Hi Dears
I have 3 dropdown lists inside an Update Panel.
Country,State,Area respectively. These 3 Dropdowns are related.
If I choose a Country Name from the Country dropdown then all the states of selected country will be available in state dropdown . It works fine for first postback only...
the state dropdown is not refreshing for all postback except the first postback..
I have used
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlCountry" EventName="SelectedIndexChanged"/>
<asp:AsyncPostBackTrigger ControlID="ddlState" EventName="SelectedIndexChanged"/>
<asp:AsyncPostBackTrigger ControlID="ddlArea" EventName="SelectedIndexChanged"/></Triggers>
仍然没有刷新第二次回发的状态下拉菜单..
如果有人对此有任何想法,请帮帮我...
在此先感谢... :)
Still not refreshing the state dropdown from the second postback..
Please help me if anyone has Idea about this...
Thanks in advance... :)
推荐答案
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Learn How Add ASP.NET 3.5 AJAX UpdatePanel Triggers</title></head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Country"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<br />
<asp:Label ID="Label2" runat="server" Text="State"></asp:Label>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"
Enabled="False" onselectedindexchanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList>
<br />
<asp:Label ID="Label3" runat="server" Text="City"></asp:Label>
<asp:DropDownList ID="DropDownList3" runat="server" AutoPostBack="True"
Enabled="False" onselectedindexchanged="DropDownList3_SelectedIndexChanged">
</asp:DropDownList>
<br />
<asp:Label ID="Label4" runat="server"></asp:Label>
<br />
<br />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
背后的代码:
CODE BEHIND:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
List<string> l1 = new List<string>();
l1.Add(" ");
l1.Add("India");
l1.Add("USA");
foreach (string item in l1)
{
DropDownList1.Items.Add(item);
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList2.Enabled = true;
DropDownList3.Enabled = false;
Label4.Text = "";
List<string> l2 = new List<string>();
if (DropDownList1.SelectedItem.Text == "India")
{
DropDownList2.Items.Clear();
l2.Add(" ");
l2.Add("Maharashtra");
l2.Add("Goa");
foreach (string item in l2)
{
DropDownList2.Items.Add(item);
}
}
else
{
DropDownList2.Items.Clear();
l2.Add(" ");
l2.Add("Indiana");
l2.Add("Texas");
foreach (string item in l2)
{
DropDownList2.Items.Add(item);
}
}
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList3.Enabled = true;
List<string> l3 = new List<string>();
if (DropDownList2.SelectedItem.Text == "Maharashtra")
{
DropDownList3.Items.Clear();
l3.Add(" ");
l3.Add("Pune");
l3.Add("Mumbai");
foreach (string item in l3)
{
DropDownList3.Items.Add(item);
}
}
else if (DropDownList2.SelectedItem.Text == "Goa")
{
DropDownList3.Items.Clear();
l3.Add(" ");
l3.Add("Panji");
l3.Add("Vasco");
foreach (string item in l3)
{
DropDownList3.Items.Add(item);
}
}
else if (DropDownList2.SelectedItem.Text == "Indiana")
{
DropDownList3.Items.Clear();
l3.Add(" ");
l3.Add("Wilkinson");
l3.Add("Morocco");
foreach (string item in l3)
{
DropDownList3.Items.Add(item);
}
}
else if (DropDownList2.SelectedItem.Text == "Texas")
{
DropDownList3.Items.Clear();
l3.Add(" ");
l3.Add("Archer City");
l3.Add("Bryan");
foreach (string item in l3)
{
DropDownList3.Items.Add(item);
}
}
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
Label4.Text = DropDownList1.SelectedItem.Text.ToString() + " " + DropDownList2.SelectedItem.Text.ToString() + " " + DropDownList3.SelectedItem.Text.ToString();
}
}
这篇关于在ASP .Net中的第一个PostBack之后,Update Panel中的下拉列表不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!