ASP.Net里面怎样实现两个dropdownlist联动
dropdownlist1中有A.B.C3项A.B.C中分别有几组数据要在dropdownlist1选A时,dropdownlist2中显示A的数据.页面刷新也可以.麻烦...
dropdownlist1中有A.B.C3项 A.B.C中分别有几组数据 要在dropdownlist1选A时,dropdownlist2中显示A的数据.页面刷新也可以.麻烦告诉的具体点 希望能把SelectedIndexChanged事件中的代码给出来
展开
1个回答
2013-12-20
展开全部
你好,这是我以前学习的时候做的。希望能帮到你。 在页面添加两个dorpdownlist 和一个label控件protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
ArrayList Myarray;
switch (DropDownList1.SelectedValue)
{
case "100":
Myarray = new ArrayList();
Myarray.Add(new ListItem("朝阳区", "0"));
Myarray.Add(new ListItem("宜武区", "1"));
Myarray.Add(new ListItem("丰台区", "2"));
DropDownList2.DataSource = Myarray;
DropDownList2.DataBind();
Label1.Text = "";
break;
case "101": Myarray = new ArrayList();
Myarray.Add(new ListItem("白云区", "0"));
Myarray.Add(new ListItem("南沙区", "1"));
Myarray.Add(new ListItem("天河区", "2"));
DropDownList2.DataSource = Myarray;
DropDownList2.DataBind();
Label1.Text = "";
break;
case "102": Myarray = new ArrayList();
Myarray.Add(new ListItem("澄海区", "0"));
Myarray.Add(new ListItem("龙湖区", "1"));
Myarray.Add(new ListItem("新津区", "2"));
DropDownList2.DataSource = Myarray;
DropDownList2.DataBind();
Label1.Text = "";
break; }
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
Label1.Text = DropDownList1.SelectedItem.Text + DropDownList2.SelectedItem.Text;
}
{
ArrayList Myarray;
switch (DropDownList1.SelectedValue)
{
case "100":
Myarray = new ArrayList();
Myarray.Add(new ListItem("朝阳区", "0"));
Myarray.Add(new ListItem("宜武区", "1"));
Myarray.Add(new ListItem("丰台区", "2"));
DropDownList2.DataSource = Myarray;
DropDownList2.DataBind();
Label1.Text = "";
break;
case "101": Myarray = new ArrayList();
Myarray.Add(new ListItem("白云区", "0"));
Myarray.Add(new ListItem("南沙区", "1"));
Myarray.Add(new ListItem("天河区", "2"));
DropDownList2.DataSource = Myarray;
DropDownList2.DataBind();
Label1.Text = "";
break;
case "102": Myarray = new ArrayList();
Myarray.Add(new ListItem("澄海区", "0"));
Myarray.Add(new ListItem("龙湖区", "1"));
Myarray.Add(new ListItem("新津区", "2"));
DropDownList2.DataSource = Myarray;
DropDownList2.DataBind();
Label1.Text = "";
break; }
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
Label1.Text = DropDownList1.SelectedItem.Text + DropDownList2.SelectedItem.Text;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询