Second-level interaction with AjaxPro

Source: Internet
Author: User
<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Test. aspx. cs" Inherits = "Test" %> <! DOCTYPE html PUBLIC "-// W3C // Dtd XHTML 1.0 Transitional // EN" "http://www.w3.org/tr/xhtml1/Dtd/xhtml1-transitional.dtd"> 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;/*** Description: This article shows how to use AjaxPro to interact with the server, in addition, it also shows the set that can be directly called by the server in Js and the attribute * Author: Zhou Gong * Date: * Starting address: 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 <State> stateList = new List <State> (10); stateList. add (new State (0, "select city"); // default stateList. add (new State (1, "Beijing"); stateList. add (new State (2, "Tianjin"); stateList. add (new State (3, "Shanghai"); stateList. add (new State (4, "Hubei"); stateList. add (new State (5, "Hunan"); stateList. add (new State (6, "Shanxi"); ddlStateList. dataSource = stateList; ddlStateList. dataBind (); ddlStateList. attributes ["onchange"] = "ShowCity (this. options [selectedIndex]. value) ";} AjaxPro. utility. registerTypeForAjax (typeof (Test); // register} [AjaxPro. ajaxMethod] public List <City> GetCityList (int stateId) {// Haha, all of which are List of cities or areas I know <City> cityList = new List <City> (12 ); cityList. add (new City (11, "Haidian District", 1); cityList. add (new City (12, "Chaoyang District", 1); cityList. add (new City (13, "Dagang district", 2); cityList. add (new City (14, "Nankai district", 2); cityList. add (new City (15, "Putuo District", 3); cityList. add (new City (16, "Huangpu District", 3); cityList. add (new City (17, "Huanggang City", 4); cityList. add (new City (18, "Jingzhou", 4); cityList. add (new City (19, "Changsha City", 5); cityList. add (new City (20, "Yueyang City", 5); cityList. add (new City (21, "Taiyuan City", 6); cityList. add (new City (22, "Datong City", 6); List <City> tempList = new List <City> (); for (int I = 0; I <cityList. count; I ++) {if (cityList [I]. stateId = stateId) {tempList. add (cityList [I]) ;}} return tempList ;}} /// <summary> /// province information /// </summary> public class State {private int stateId; private string stateName; /// <summary> /// province name /// </summary> public string StateName {get {return stateName;} set {stateName = value ;}} /// <summary> /// province no. /// </summary> public int StateId {get {return stateId;} set {stateId = value ;}} public State (int stateId, string stateName) {this. stateId = stateId; this. stateName = stateName ;}/// <summary> // City information /// </summary> public class City {private int cityId; private int stateId; private string cityName; /// <summary> // city name // </summary> public string CityName {get {return cityName;} set {cityName = value ;}} /// <summary> /// province ID of the city /// </summary> public int StateId {get {return stateId;} set {stateId = value ;}} /// <summary> // city no. // </summary> 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 ;}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.