Development environment VS.NET 2005 C# Oracle AjaxPro
I have been busy recently and have no time to explain in detail, so I will post the general source code to see for myself.
For performance reasons, the province and city levels are written as JS arrays, and the county and district (town) levels are written in Oracle. Trigger C# to read the database through JS, then pass the data back to JS, and then bind it for display.
Operation <select> uses the more general createElement() instead of using options.add()
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Area.aspx.cs" Inherits="Area" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns=" http://www.w3.org/1999/xhtml " >
<head runat="server">
<title>Region</title>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td>
<select id="SF">
<option selected="selected">—Please select—</option>
</select>
</td>
<td>
<select id="CS">
<option selected="selected">—Please select—</option>
</select>
</td>
<td>
<select id="Xian">
<option selected="selected">—Please select—</option>
</select>
</td>
<td>
<select id="Zhen">
<option selected="selected">—Please select—</option>
</select>
</td>
</tr>
</table>
<script type="text/javascript">
var aDQ=new Array();
aDQ[0]=["11","Beijing","0","bj"];
aDQ[1]=["12","Tianjin","0","tj"];
aDQ[2]=["13","Hebei","0","hb"];
aDQ[3]=["14","Shanxi","0","shang"];
aDQ[4]=["15","Inner Mongolia","0","nmg"];
aDQ[5]=["21","Liaoning","0","ln"];
aDQ[6]=["22","Jilin","0","jl"];
aDQ[7]=["23","Heilongjiang","0","hlj"];
aDQ[8]=["31","Shanghai","0","sh"];
aDQ[9]=["32","Jiangsu","0","js"];
aDQ[10]=["33","Zhejiang","0","zhej"];
aDQ[11]=["34","Anhui","0","ah"];
aDQ[12]=["35","Fujian","0","fj"];
aDQ[13]=["36","Jiangxi","0","jw"];
aDQ[14]=["37","Shandong","0","sd"];
aDQ[15]=["41","Henan","0","he"];
aDQ[16]=["42","Hubei","0","hu"];
aDQ[17]=["43","Hunan","0","hn"];
aDQ[18]=["44","Guangdong","0","gd"];
aDQ[19]=["45","Guangxi","0","gx"];
aDQ[20]=["46","Hainan","0","hain"];
aDQ[21]=["50","Chongqing","0","cq"];
aDQ[22]=["51","Sichuan","0","sc"];
aDQ[23]=["52","Guizhou","0","gui"];
aDQ[24]=["53","Yunnan","0","yn"];
aDQ[25]=["54","Tibet","0","wc"];
aDQ[26]=["61","Shaanxi","0","shangx"];
aDQ[27]=["62","Gansu","0","gs"];
aDQ[28]=["63","Qinghai","0","qh"];
aDQ[29]=["64","Ningxia","0","nx"];
aDQ[30]=["65","Xinjiang","0","xj"];
aDQ[31]=["71","Taiwan","0","tw"];
aDQ[32]=["81","Hong Kong","0","xg"];
aDQ[33]=["82","Macau","0","am"];
aDQ[34]=["1101","Beijing City","11","bjcq"];
aDQ[35]=["1102","Beijing County","11","bjxq"];
aDQ[36]=["1201","Tianjin City","12","tjcq"];
aDQ[37]=["1202","Tianjin County","12","tjxq"];
aDQ[38]=["1301","Shijiazhuang","13","sjz"];
aDQ[39]=["1302","Tangshan","13","hbts"];
aDQ[40]=["1303","Qinhuangdao","13","qhd"];
aDQ[41]=["1304","Handan","13","hd"];
aDQ[42]=["1305","Xingtai","13","hbxt"];
aDQ[43]=["1306","Baoding","13","bd"];
aDQ[44]=["1307","Zhangjiakou","13","zjk"];
aDQ[45]=["1308","Chengde","13","cd"];
aDQ[46]=["1309","Cangzhou","13","hbcz"];
aDQ[47]=["1310","Langfang","13","lf"];
aDQ[48]=["1311","Hengshui","13","hbhs"];
aDQ[49]=["1401","Taiyuan","14","ty"];
aDQ[50]=["1402","Datong","14","dt"];
aDQ[51]=["1403","Yangquan","14","yq"];
aDQ[52]=["1404","Changzhi","14","swcz"];
aDQ[53]=["1405","Jincheng","14","swjc"];
aDQ[54]=["1406","Shuozhou","14","swsz"];
aDQ[55]=["1501","Hohhot","15","hhht"];
aDQ[56]=["1502","Baotou","15","bt"];
aDQ[57]=["1503","Wuhai","15","nmgwh"];
aDQ[58]=["1504","Chifeng","15","cf"];
aDQ[59]=["1521","Hulunbuir League","15","hlbem"];
aDQ[60]=["1522","Xing'an League","15","xam"];
aDQ[61]=["1523","Zhelimeng","15","zlmm"];
aDQ[62]=["1525","Xilingol League","15","wlglm"];
aDQ[63]=["1526","Ulanqab League","15","wlcbm"];
aDQ[64]=["1527","Ordos","15","eeds"];
aDQ[65]=["1528","Bayannur League","15","bynem"];
aDQ[66]=["1529","Alxa League","15","alsm"];
aDQ[67]=["2101","Shenyang","21","lnsy"];
aDQ[68]=["2102","Dalian","21","dl"];
aDQ[69]=["2103","Anshan","21","as"];
aDQ[70]=["2104","Fushun","21","lnfs"];
aDQ[71]=["2105","Benxi","21","bx"];
aDQ[72]=["2106","Dandong","21","dd"];
aDQ[73]=["2107","Jinzhou","21","jz"];
aDQ[74]=["2108","Yingkou","21","yk"];
aDQ[75]=["2109","Fuxin","21","fx"];
aDQ[76]=["2110","Liaoyang","21","lnly"];
aDQ[77]=["2111","Panjin","21","pj"];
aDQ[78]=["2112","Tieling","21","lntl"];
aDQ[79]=["2113","Chaoyang","21","cy"];
aDQ[80]=["2114","Huludao","21","hld"];
aDQ[81]=["2201","Changchun","22","cc"];
aDQ[82]=["2202","Jilin","22","jljl"];
aDQ[83]=["2203","Siping","22","sp"];
aDQ[84]=["2204","Liaoyuan","22","jlly"];
aDQ[85]=["2205","Tonghua","22","th"];
aDQ[86]=["2206","白山","22","bs"];
aDQ[87]=["2207","松元","22","jlsy"];
aDQ[88]=["2208","Baicheng","22","bc"];
aDQ[89]=["2224","Yanbian","22","jlyb"];
aDQ[90]=["2301","Harbin","23","heb"];
aDQ[91]=["2302","Qiqihar","23","qqhe"];
aDQ[92]=["2303","Jixi","23","hljjw"];
aDQ[93]=["2304","Hegang","23","hg"];
aDQ[94]=["2305","Shuangyashan","23","sys"];
aDQ[95]=["2306","Daqing","23","dq"];
aDQ[96]=["2307","Yichun","23","hljyc"];
aDQ[97]=["2308","Jiamusi","23","jms"];
aDQ[98]=["2309","Qitaihe","23","qth"];
aDQ[99]=["2310","Mudanjiang","23","mdj"];
aDQ[100]=["2311","Heihe","23","hh"];
aDQ[101]=["3101","Shanghai urban area","31","shsq"];
aDQ[102]=["3102","Shanghai County","31","shxq"];
aDQ[103]=["3201","Nanjing","32","nj"];
aDQ[104]=["3202","Wuxi","32","ww"];
aDQ[105]=["3203","Xuzhou","32","xz"];
aDQ[106]=["3204","Changzhou","32","jscz"];
aDQ[107]=["3205","Suzhou","32","shu"];
aDQ[108]=["3206","Nantong","32","nt"];
aDQ[109]=["3207","Lianyungang","32","lyg"];
aDQ[110]=["3208","Huaian","32","ha"];
aDQ[111]=["3209","Yancheng","32","jsyc"];
aDQ[112]=["3210","Yangzhou","32","yz"];
aDQ[113]=["3211","Zhenjiang","32","jszj"];
aDQ[114]=["3212","Taizhou","32","tz"];
aDQ[115]=["3213","Suqian","32","sq"];
aDQ[116]=["3301","Hangzhou","33","han"];
aDQ[117]=["3302","Ningbo","33","nb"];
aDQ[118]=["3303","Wenzhou","33","zjwz"];
aDQ[119]=["3304","Jiaxing","33","jx"];
aDQ[120]=["3305","Huzhou","33","zjhz"];
aDQ[121]=["3306","Shaoxing","33","sx"];
aDQ[122]=["3307","Jinhua","33","jh"];
aDQ[123]=["3308","Quzhou","33","zjqz"];
aDQ[124]=["3309","Zhoushan","33","zjzs"];
aDQ[125]=["3310","Taizhou","33","zjtz"];
aDQ[126]=["3311","Yiwu","33","yw"];
aDQ[127]=["3325","Lishui","33","zjls"];
aDQ[128]=["3401","Hefei","34","hf"];
aDQ[129]=["3402","Wuhu","34","wh"];
aDQ[130]=["3403","Bengbu","34","bb"];
aDQ[131]=["3404","Huainan","34","hnx"];
aDQ[132]=["3405","Ma'anshan","34","mas"];
aDQ[133]=["3406","Huaibei","34","huib"];
aDQ[134]=["3407","Tongling","34","tl"];
aDQ[135]=["3408","Anqing","34","aq"];
aDQ[136]=["3410","Huangshan","34","hs"];
aDQ[137]=["3411","Chuzhou","34","ahcz"];
aDQ[138]=["3412","Fuyang","34","fy"];
aDQ[139]=["3413","Suzhou","34","ahsz"];
aDQ[140]=["3416","Haozhou","34","ahhz"];
aDQ[141]=["51011117","Chizhou","34",""];
aDQ[142]=["51011118","六安","34",""];
aDQ[143]=["51011119","Xuancheng","34",""];
aDQ[144]=["3501","Fuzhou","35","fz"];
aDQ[145]=["3502","Xiamen","35","xm"];
aDQ[146]=["3503","Putian","35","pt"];
aDQ[147]=["3504","三明","35","sm"];
aDQ[148]=["3505","Quanzhou","35","qz"];
aDQ[149]=["3506","Zhangzhou","35","fzz"];
aDQ[150]=["3507","Nanping","35","np"];
aDQ[151]=["3508","Longyan","35","fjly"];
aDQ[152]=["3509","Ningde","35","fjnd"];
aDQ[153]=["3601","Nanchang","36","jwnc"];
aDQ[154]=["3602","Jingdezhen","36","jdz"];
aDQ[155]=["3603","Pingxiang","36","px"];
aDQ[156]=["3604","Jiujiang","36","jj"];
aDQ[157]=["3605","Xinyu","36","xy"];
aDQ[158]=["3606","Yingtan","36","jwyt"];
aDQ[159]=["3607","Ganzhou","36","jwgz"];
aDQ[160]=["3701","Jinan","37","jn"];
aDQ[161]=["3702","Qingdao","37","qd"];
aDQ[162]=["3703","Zibo","37","zb"];
aDQ[163]=["3704","Zaozhuang","37","sdzz"];
aDQ[164]=["3705","Dongying","37","sddy"];
aDQ[165]=["3706","Yantai","37","yt"];
aDQ[166]=["3707","Weifang","37","wf"];
aDQ[167]=["3708","Jining","37","sdjn"];
aDQ[168]=["3709","Taian","37","ta"];
aDQ[169]=["3710","Weihai","37","sdwh"];
aDQ[170]=["3711","Rizhao","37","rz"];
aDQ[171]=["3712","Laiwu","37","lw"];
aDQ[172]=["3713","Linyi","37","ly"];
aDQ[173]=["3714","Texas","37","sddz"];
aDQ[174]=["3715","Liaocheng","37","lc"];
aDQ[175]=["4101","Zhengzhou","41","zhen"];
aDQ[176]=["4102","Kaifeng","41","kf"];
aDQ[177]=["4103","Luoyang","41","hnly"];
aDQ[178]=["4104","Pingdingshan","41","pds"];
aDQ[179]=["4105","Anyang","41","ay"];
aDQ[180]=["4106","Hebi","41","hebi"];
aDQ[181]=["4107","Xinxiang","41","xx"];
aDQ[182]=["4108","Jiaozuo","41","hnjz"];
aDQ[183]=["4109","Puyang","41","zy"];
aDQ[184]=["4110","Xuchang","41","xc"];
aDQ[185]=["4111","Luohe","41","zhe"];
aDQ[186]=["4112","Sanmenxia","41","smx"];
aDQ[187]=["4113","Nanyang","41","ny"];
aDQ[188]=["4114","Shangqiu","41","hnsq"];
aDQ[189]=["4115","Xinyang","41","hnxy"];
aDQ[190]=["4201","Wuhan","42","hbwh"];
aDQ[191]=["4202","Yellowstone","42","hhs"];
aDQ[192]=["4203","Shiyan","42","sy"];
aDQ[193]=["4205","Yichang","42","hbyc"];
aDQ[194]=["4206","Xiangfan","42","xf"];
aDQ[195]=["4207","Ezhou","42","ez"];
aDQ[196]=["4208","Jingmen","42","hbjm"];
aDQ[197]=["4209","Xiaogan","42","hbxg"];
aDQ[198]=["4210","Jingzhou","42","hbjz"];
aDQ[199]=["4211","Huanggang","42","hbhg"];
aDQ[200]=["4212","Xianning","42","xn"];
aDQ[201]=["4228","Enshi","42","es"];
aDQ[202]=["4301","Changsha","43","cs"];
aDQ[203]=["4302","Zhuzhou","43","hnzz"];
aDQ[204]=["4303","Xiangtan","43","xt"];
aDQ[205]=["4304","Hengyang","43","hnhy"];
aDQ[206]=["4305","Shaoyang","43","shao"];
aDQ[207]=["4306","Yueyang","43","yy"];
aDQ[208]=["4307","Changde","43","hncd"];
aDQ[209]=["4308","Zhangjiajie","43","zjj"];
aDQ[210]=["4309","Yiyang","43","hnyy"];
aDQ[211]=["4310","Chenzhou","43","hncz"];
aDQ[212]=["4311","Yongzhou","43","hnyz"];
aDQ[213]=["4312","Huaihua","43","hnhh"];
aDQ[214]=["4331","Xiangxi","43","xw"];
aDQ[215]=["4401","Guangzhou","44","gz"];
aDQ[216]=["4402","Shaoguan","44","sg"];
aDQ[217]=["4403","Shenzhen","44","sz"];
aDQ[218]=["4404","Zhuhai","44","zh"];
aDQ[219]=["4405","Shantou","44","st"];
aDQ[220]=["4406","Foshan","44","fs"];
aDQ[221]=["4407","Jiangmen","44","jm"];
aDQ[222]=["4408","Zhanjiang","44","zj"];
aDQ[223]=["4409","Maoming","44","mm"];
aDQ[224]=["4412","Zhaoqing","44","zq"];
aDQ[225]=["4413","Huizhou","44","hz"];
aDQ[226]=["4414","Meizhou","44","mz"];
aDQ[227]=["4415","Shantou","44","shanw"];
aDQ[228]=["4416","Heyuan","44","hy"];
aDQ[229]=["4417","Yangjiang","44","yj"];
aDQ[230]=["4418","Qingyuan","44","qy"];
aDQ[231]=["4419","Dongguan","44","dz"];
aDQ[232]=["4420","Zhongshan","44","zs"];
aDQ[233]=["4451","Chaozhou","44","cz"];
aDQ[234]=["4452","Jieyang","44","jy"];
aDQ[235]=["4453","Yunfu","44","yf"];
aDQ[236]=["4501","Nanning","45","nn"];
aDQ[237]=["4502","Liuzhou","45","lz"];
aDQ[238]=["4503","Guilin","45","gwgl"];
aDQ[239]=["4504","Wuzhou","45","gwwz"];
aDQ[240]=["4505","Beihai","45","bh"];
aDQ[241]=["4506","Fangchenggang","45","fcg"];
aDQ[242]=["4507","Qinzhou","45","gqz"];
aDQ[243]=["4508","Guigang","45","gg"];
aDQ[244]=["4509","Yulin","45","yl"];
aDQ[245]=["4601","Haikou","46","hk"];
aDQ[246]=["4602","Sanya","46","hnsy"];
aDQ[247]=["5002","Chongqing County","50","zqxq"];
aDQ[248]=["5003","Chongqing City","50","zqcq"];
aDQ[249]=["5101","Chengdu","51","sccd"];
aDQ[250]=["5103","Zigong","51","zg"];
aDQ[251]=["5104","Panzhihua","51","pzh"];
aDQ[252]=["5105","Luzhou","51","sczz"];
aDQ[253]=["5106","Deyang","51","dy"];
aDQ[254]=["5107","Mianyang","51","my"];
aDQ[255]=["5108","Guangyuan","51","gy"];
aDQ[256]=["5109","Suining","51","sn"];
aDQ[257]=["5110","Neijiang","51","scnj"];
aDQ[258]=["5111","Leshan","51","ls"];
aDQ[259]=["5113","Nanchong","51","nc"];
aDQ[260]=["5115","Yibin","51","yb"];
aDQ[261]=["5116","Guang'an","51","ga"];
aDQ[262]=["5130","Dazhou","51","scdz"];
aDQ[263]=["5132","Ababa","51","ab"];
aDQ[264]=["5133","Ganzi","51","scgz"];
aDQ[265]=["5134","Liangshan","51","scls"];
aDQ[266]=["5201","Guiyang","52","gzgy"];
aDQ[267]=["5202","Liupanshui","52","lps"];
aDQ[268]=["5203","Zunyi","52","gzzy"];
aDQ[269]=["5223","Southwestern Guizhou","52","qwn"];
aDQ[270]=["5226","Qiandongnan","52","qdn"];
aDQ[271]=["5227","Qiannan","52","qn"];
aDQ[272]=["5301","Kunming","53","km"];
aDQ[273]=["5303","Qujing","53","qj"];
aDQ[274]=["5304","Yuxi","53","yx"];
aDQ[275]=["5323","Chuxiong","53","cx"];
aDQ[276]=["5325","红河","53","ynhh"];
aDQ[277]=["5326","Wenshan","53","ws"];
aDQ[278]=["5328","Xishuangbanna","53","wsbn"];
aDQ[279]=["5329","Dali","53","yndl"];
aDQ[280]=["5331","Dehong","53","dh"];
aDQ[281]=["5333","Nujiang","53","nuj"];
aDQ[282]=["5334","Diqing","53","yndq"];
aDQ[283]=["51010963","Lijiang City","53","ljs"];
aDQ[284]=["51012663","Baoshan","53",""];
aDQ[285]=["5401","Lhasa","54","wcls"];
aDQ[286]=["6101","Xi'an","61","wa"];
aDQ[287]=["6102","Tongchuan","61","tc"];
aDQ[288]=["6103","Baoji","61","swbj"];
aDQ[289]=["6104","Xianyang","61","swxy"];
aDQ[290]=["6105","Weinan","61","swwn"];
aDQ[291]=["6106","Yan'an","61","ya"];
aDQ[292]=["6107","Hanzhong","61","swhz"];
aDQ[293]=["6201","Lanzhou","62","gslz"];
aDQ[294]=["6202","Jiayuguan","62","jyg"];
aDQ[295]=["6203","Jinchang","62","jc"];
aDQ[296]=["6204","silver","62","by"];
aDQ[297]=["6205","Tianshui","62","ts"];
aDQ[298]=["6229","Linxia","62","lx"];
aDQ[299]=["6230","Gannan","62","gn"];
aDQ[300]=["6301","Xining","63","wn"];
aDQ[301]=["6322","海北","63","hai"];
aDQ[302]=["6323","Huang Nan","63","huang"];
aDQ[303]=["6325","Hainan","63","qhhn"];
aDQ[304]=["6326","Guoluo","63","gl"];
aDQ[305]=["6327","Yushu","63","ys"];
aDQ[306]=["6328","海西","63","hw"];
aDQ[307]=["6401","Yinchuan","64","yc"];
aDQ[308]=["6402","Shizuishan","64","szs"];
aDQ[309]=["6403","Wuzhong","64","wz"];
aDQ[310]=["6405","中卫","64","zw"];
aDQ[311]=["6501","Urumqi","65","wlmq"];
aDQ[312]=["6502","Klmy","65","klmy"];
aDQ[313]=["6523","Changji","65","cj"];
aDQ[314]=["6527","Bortala","65","betl"];
aDQ[315]=["6528","Bayingoleng","65","bygl"];
aDQ[316]=["6530","Kizilsu Kirgiz","65","kzlskekz"];
aDQ[317]=["6540","Ili","65","xjyl"];
aDQ[318]=["7101","Taipei","71",""];
aDQ[319]=["7102","Yilan","71",""];
aDQ[320]=["7103","Taoyuan","71",""];
aDQ[321]=["7104","Hsinchu","71",""];
aDQ[322]=["7105","Miaoli","71",""];
aDQ[323]=["7106","Taichung","71",""];
aDQ[324]=["7107","Changhua","71",""];
aDQ[325]=["7108","Nantou","71",""];
aDQ[326]=["7109","Yunlin","71",""];
aDQ[327]=["7110","Chiayi","71",""];
aDQ[328]=["7111","Tainan","71",""];
aDQ[329]=["7112","Kaohsiung","71",""];
aDQ[330]=["7113","Pingtung","71",""];
aDQ[331]=["7114","Taitung","71",""];
aDQ[332]=["7115","Hualien","71",""];
aDQ[333]=["7116","Penghu","71",""];
aDQ[334]=["7117","Keelung","71",""];
aDQ[335]=["7118","Kinmen","71",""];
aDQ[336]=["7119","Mazu","71",""];
aDQ[337]=["8101","New Territories","81",""];
aDQ[338]=["8102","Hong Kong Island","81",""];
aDQ[339]=["8103","Lantau","81",""];
aDQ[340]=["8104","Kowloon","81",""];
aDQ[341]=["8201","Macau Island","82",""];
aDQ[342]=["8202","Taipa","82",""];
aDQ[343]=["8203","Coloane","82",""];
//Create a drop-down box through DOM http://www.downcodes.com/qq.asp
//obj: options data set of drop-down box
//id: the id of the drop-down box
function CreateDropDownList(obj,id)
...{
var sel=document.getElementById(id);
sel.options.length=1; //Save "—Please select—"
//Array storage is commonly used for provinces and cities, and C# is used to read from the database for counties and towns.
if(obj==null)return;
if(obj instanceof Array)
...{
for(var i=0;i<obj.length;i++)
...{
var op=document.createElement("option");
op.setAttribute("value",obj[i][0]);
var txt=document.createTextNode(obj[i][1]);
op.appendChild(txt);
sel.appendChild(op);
}
}
else
...{
for(var i=0;i<obj.Rows.length;i++) //Note that this is length, not Count
...{
var op=document.createElement("option");
op.setAttribute("value",obj.Rows[i].ID); //Note that it is case sensitive
var txt=document.createTextNode(obj.Rows[i].NAME); //The column names of the root DataTable must be consistent
op.appendChild(txt);
sel.appendChild(op);
}
}
//Bind the next drop-down box
switch(id)
...{
case "SF":sel.onchange=function()......{ClearXianZhen();CreateDropDownList(GetArray(this.value),"CS");};break;
case "CS":sel.onchange=function()......{ClearZhen();CreateDropDownList(Area.GetDataTable(this.value,AreaEnum.Xian).value,"Xian");};break; / /JS passes parameters to C# and gets the return value of C#
case "Xian":sel.onchange=function()...{CreateDropDownList(Area.GetDataTable(this.value,AreaEnum.Zhen).value,"Zhen");};break; //Return value. value
default:sel.onchange=function()......{alert(this.value);};break;
}
}
//Execution entry
var arr=GetArray("0");
CreateDropDownList(arr,"SF");
//Get the required array
//tar=Province ID to which it belongs
function GetArray(val)
...{
var temp=new Array();
var j=0;
for(var i=0;i<aDQ.length;i++)
...{
if(aDQ[i][2].toString()==val)
...{
temp[j]=aDQ[i];
//temp[j].push(aDQ[i]);
j++;
}
}
return temp;
}
//Clear the "Town" drop-down box
function ClearZhen()
...{
CreateDropDownList(null,"Zhen");
}
//Clear the "County" and "Town" drop-down boxes
function ClearXianZhen()
...{
CreateDropDownList(null,"Xian");
CreateDropDownList(null,"Zhen");
}
</script>
</form>
</body>
</html>
using System;
using System.Data;
using System.Data.OracleClient;
public partial class Area : System.Web.UI.Page
...{
protected void Page_Load(object sender, EventArgs e)
...{
//Register C# classes and enumerations into JS respectively
AjaxPro.Utility.RegisterTypeForAjax(typeof(Area));
AjaxPro.Utility.RegisterEnumForAjax(typeof(AreaEnum));
}
/**//// <summary>
/// Get the data required by the drop-down box
/// </summary>
/// <param name="UpID">Upper level ID</param>
/// <param name="ae">County/Town</param>
/// <returns>Return DataTable</returns>
[AjaxPro.AjaxMethod]
public DataTable GetDataTable(string UpID, AreaEnum ae)
...{
if (String.IsNullOrEmpty(UpID))
return null;
string link = "server=XXX;user=XXX;pwd=XXX;";
OracleConnection conn = new OracleConnection(link);
//The column names in the DataTable returned by Oracle are all in uppercase letters. Remember to use uppercase letters when fetching values on the page.
string sql;
if (Enum.Equals(ae, AreaEnum.Xian))
sql = "SELECT id,name FROM City WHERE THREEID=0 AND TWOID=" + UpID;
else
sql = "SELECT id,name FROM City WHERE THREEID=" + UpID;
OracleDataAdapter adapter = new OracleDataAdapter(sql, conn);
DataTable table = new DataTable();
adapter.Fill(table);
return table;
}
}
/**//// <summary>
/// Region enumeration
/// </summary>
public enum AreaEnum
...{
/**//// <summary>
/// county
/// </summary>
Xian,
/**//// <summary>
/// town
/// </summary>
Zhen
}
At this point, the basic functions are implemented, and there are also some functions (determining the region through domain nameIP and binding directly, saving the selected region, conveniently reading/saving city information to make controls, etc.). I’ll finish it when I have time.
Remember to add<httpHandlers>
in <system.web> of Web.config
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro.2"/>
</httpHandlers>