本文介绍了在dropdownlist中选择值,然后在asp中的另一个dropdownlist中显示velue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下拉列表中选择值,然后在asp中的另一个下拉列表中显示velue. 要填充数据库,请调用数据库以填充下拉列表. 后面的代码
protected void Page_Load(object sender, EventArgs e) { DropDownList1.Items.Add(new ListItem("Sandip", "1")); DropDownList1.Items.Add(new ListItem("Jon", "2")); DropDownList1.Items.Add(new ListItem("Michael", "3")); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { DropDownList2.Items.Clear(); if (DropDownList1.SelectedIndex == 0) { DropDownList2.Items.Add(new ListItem("DOT.NET", "1")); DropDownList2.Items.Add(new ListItem("C#", "2")); DropDownList2.Items.Add(new ListItem("ASP.NET", "3")); DropDownList2.Items.Add(new ListItem("LINQ", "4")); } else if (DropDownList1.SelectedIndex == 1) { DropDownList2.Items.Add(new ListItem("DOT.NET", "1")); DropDownList2.Items.Add(new ListItem("VB.NET", "2")); DropDownList2.Items.Add(new ListItem("ASP.NET", "3")); } else if (DropDownList1.SelectedIndex == 2) { DropDownList2.Items.Add(new ListItem("PHP", "1")); DropDownList2.Items.Add(new ListItem("MYSQL", "2")); } }aspx代码
<asp:dropdownlist id="DropDownList1" runat="server" autopostback="True" xmlns:asp="#unknown"> onselectedindexchanged="DropDownList1_SelectedIndexChanged"> </asp:dropdownlist> <br /> <br /> <asp:dropdownlist id="DropDownList2" runat="server" xmlns:asp="#unknown"> </asp:dropdownlist>欢呼声
这称为级联dropdownlist.这是一篇介绍两种方法的文章.也包含示例项目.参照它,看看是否有帮助 面向初学者的AJAX(第2部分)-使用XMLHttpRequest和jQuery AJAX实施级联下拉列表 [ ^ ]
这应该为您提供一些您需要的信息 级联下拉列表 [ ^ ]
selected value in dropdownlist and then show velue in another dropdownlist in asp
解决方案 Here is the code for you. To fill up the database, call the database to populate dropdown. code behind protected void Page_Load(object sender, EventArgs e) { DropDownList1.Items.Add(new ListItem("Sandip", "1")); DropDownList1.Items.Add(new ListItem("Jon", "2")); DropDownList1.Items.Add(new ListItem("Michael", "3")); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { DropDownList2.Items.Clear(); if (DropDownList1.SelectedIndex == 0) { DropDownList2.Items.Add(new ListItem("DOT.NET", "1")); DropDownList2.Items.Add(new ListItem("C#", "2")); DropDownList2.Items.Add(new ListItem("ASP.NET", "3")); DropDownList2.Items.Add(new ListItem("LINQ", "4")); } else if (DropDownList1.SelectedIndex == 1) { DropDownList2.Items.Add(new ListItem("DOT.NET", "1")); DropDownList2.Items.Add(new ListItem("VB.NET", "2")); DropDownList2.Items.Add(new ListItem("ASP.NET", "3")); } else if (DropDownList1.SelectedIndex == 2) { DropDownList2.Items.Add(new ListItem("PHP", "1")); DropDownList2.Items.Add(new ListItem("MYSQL", "2")); } }aspx code
<asp:dropdownlist id="DropDownList1" runat="server" autopostback="True" xmlns:asp="#unknown"> onselectedindexchanged="DropDownList1_SelectedIndexChanged"> </asp:dropdownlist> <br /> <br /> <asp:dropdownlist id="DropDownList2" runat="server" xmlns:asp="#unknown"> </asp:dropdownlist>cheers
This is called cascading dropdownlist. here is an article that presents 2 approaches to do the same. contains sample projects too. refer it and see if it could be helpful AJAX for beginners (Part 2) - Using XMLHttpRequest and jQuery AJAX to implement a cascading dropdown[^]This should give you some information you need cascading dropdownlist [^]更多推荐
在dropdownlist中选择值,然后在asp.net中的另一个dropdownlist中显示velue
发布评论