您现在的位置是:网站首页> 编程资料编程资料

asp.net DropDownList实现二级联动效果_实用技巧_

2023-05-24 442人已围观

简介 asp.net DropDownList实现二级联动效果_实用技巧_

最近在做新闻发布系统的时候,用到了二级联动,我把使用方法记录下来,以便日后查阅以及帮助新手朋友们。下面是效果图:

下面来讲解一下实现的方法:

1.在.aspx页面中,拖入两个DroDownList控件。代码如下:

新闻风格:新闻类型:/asp:DropDownList>

2.aspx.cs页面中的代码如下:

 using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; public partial class release_News : System.Web.UI.Page { protected void DropdownList1() { DropDownList1.Items.Add(new ListItem("新闻动态")); DropDownList1.Items.Add(new ListItem("政务公开")); DropDownList1.Items.Add(new ListItem("网上办事")); } protected void DropdownList2() { switch (DropDownList1.SelectedValue) { case "新闻动态": DropDownList2.Items.Clear(); DropDownList2.Items.Add(new ListItem("工作动态")); DropDownList2.Items.Add(new ListItem("公示公告")); DropDownList2.Items.Add(new ListItem("经济新闻")); DropDownList2.Items.Add(new ListItem("省内新闻")); DropDownList2.Items.Add(new ListItem("热点新闻")); break; case "政务公开": DropDownList2.Items.Clear(); DropDownList2.Items.Add(new ListItem("领导班子")); DropDownList2.Items.Add(new ListItem("机构设置")); DropDownList2.Items.Add(new ListItem("计划规划")); break; case "网上办事": DropDownList2.Items.Clear(); DropDownList2.Items.Add(new ListItem("岗位职责")); DropDownList2.Items.Add(new ListItem("办事流程")); break; } } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DropdownList1(); DropdownList2(); } } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { DropdownList2(); } } 


使用DroDownList和js实现地区二级联动,效果图如下:

1.在aspx页面中,拖入两个DroDownList控件,代码如下:

2.er.js代码如下:

 function Dsy() { this.Items = {}; } Dsy.prototype.add = function(id,iArray) { this.Items[id] = iArray; } Dsy.prototype.Exists = function(id) { if(typeof(this.Items[id]) == "undefined") return false; return true; } function change(v){ var str="0"; for(i=0;i0 || !v) { if(dsy.Exists(str)){ ar = dsy.Items[str]; for(i=0;i

以上就是本文的全部内容,希望对大家学习APS.NET程序设计有所帮助。

-六神源码网