教你如何利用ajaxpro实现两级联动代码

来源:爱站网时间:2020-11-09编辑:网友分享
在实践中asp.net实际上,N级联动的方式和二级联动的操作方法是一样的,其实实现方法多种多样,值得我们去细细研究,别着急,爱站技术频道小编就教你如何利用ajaxpro实现两级联动代码吧!

在实践中asp.net实际上,N级联动的方式和二级联动的操作方法是一样的,其实实现方法多种多样,值得我们去细细研究,别着急,爱站技术频道小编就教你如何利用ajaxpro实现两级联动代码吧!

复制代码 代码如下:







AjaxPro实现二级联动

















AjaxPro实现二级联动 

省份


城市








using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


/**
* 写作说明:本文展示了如何利用AjaxPro与服务器交互,并且还展示了在Js中可以直接调用服务器返回的集合和直接调用服务器上class的属性
* 作者:周公
* 日期:2008-1-1
* 首发地址:http://blog.csdn.net/zhoufoxcn/
**/
public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
List stateList = new List(10);
stateList.Add(new State(0, "选择城市"));//默认选项
stateList.Add(new State(1,"北京"));
stateList.Add(new State(2, "天津"));
stateList.Add(new State(3, "上海"));
stateList.Add(new State(4, "湖北"));
stateList.Add(new State(5, "湖南"));
stateList.Add(new State(6, "山西"));
ddlStateList.DataSource = stateList;
ddlStateList.DataBind();
ddlStateList.Attributes["onchange"] = "ShowCity(this.options[selectedIndex].value)";
}
AjaxPro.Utility.RegisterTypeForAjax(typeof(Test));//注册
}
[AjaxPro.AjaxMethod]
public List GetCityList(int stateId)
{
//呵呵,都是我熟悉的城市或者区
List cityList = new List(12);
cityList.Add(new City(11, "海淀区", 1));
cityList.Add(new City(12, "朝阳区", 1));
cityList.Add(new City(13, "大港区", 2));
cityList.Add(new City(14, "南开区", 2));
cityList.Add(new City(15, "普陀区", 3));
cityList.Add(new City(16, "黄浦区", 3));
cityList.Add(new City(17, "黄冈市", 4));
cityList.Add(new City(18, "荆州市", 4));
cityList.Add(new City(19, "长沙市", 5));
cityList.Add(new City(20, "岳阳市", 5));
cityList.Add(new City(21, "太原市", 6));
cityList.Add(new City(22, "大同市", 6));
List tempList = new List();
for (int i = 0; i {
if (cityList[i].StateId == stateId)
{
tempList.Add(cityList[i]);
}
}
return tempList;
}
}
///
/// 省份信息
///

public class State
{
private int stateId;
private string stateName;
///
/// 省份名
///

public string StateName
{
get { return stateName; }
set { stateName = value; }
}

///
/// 省份编号
///

public int StateId
{
get { return stateId; }
set { stateId = value; }
}
public State(int stateId, string stateName)
{
this.stateId = stateId;
this.stateName = stateName;
}
}
///
/// 城市信息
///

public class City
{
private int cityId;
private int stateId;
private string cityName;
///
/// 城市名称
///

public string CityName
{
get { return cityName; }
set { cityName = value; }
}

///
/// 城市所在省份编号
///

public int StateId
{
get { return stateId; }
set { stateId = value; }
}

///
/// 城市编号
///

public int CityId
{
get { return cityId; }
set { cityId = value; }
}

public City(int cityId, string cityName, int stateId)
{
this.cityId = cityId;
this.cityName = cityName;
this.stateId = stateId;
}

}



以上就是爱站技术频道小编介绍的教你如何利用ajaxpro实现两级联动代码,其实同一个功能实现的方法是多种多样的,也许还有一些没有被我们挖掘出来。

上一篇:详解asp.net开发中更新组件

下一篇:ASP.NET开发之Cache的实现

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载