在dropdownlist中选择值,然后在asp.net中的另一个dropdownlist中显示velue

编程入门 行业动态 更新时间:2024-10-18 12:25:26
本文介绍了在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

本文发布于:2023-11-24 22:56:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627218.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:asp   dropdownlist   velue   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!