省市数据表结构:
ID:Guid
CreationDate:DateTime
LastModified:DateTime
RecordState:Int
LabelID:Guid
LabelCode:Varchar
ParentID:Guid
Code:Varchar
ChineseText:Nvarchar
EnglishText:Varchar
SortKeyword:Varchar
Code
// JScript 文件
function initialize()
{
var xmlhttp;
if(window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readystate==4)//判断是否是完成状态
{
if(xmlhttp.status==200)//判断是否执行成功
{
document.getElementById("ProvinceTD").innerHTML=xmlhttp.responsetext;
}
}
};
xmlhttp.open("GET","GetData.aspx?type=Province",true);
xmlhttp.send(null);
}
function initializeType()
{
var xmlhttp;
if(window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readystate==4)//判断是否是完成状态
{
if(xmlhttp.status==200)//判断是否执行成功
{
document.getElementById("TypeTD").innerHTML=xmlhttp.responsetext;
document.getElementById("TypeTD").innerHTML=xmlhttp.responsetext;
}
}
};
xmlhttp.open("GET","GetData.aspx?type=ProductType",true);
xmlhttp.send(null);
}
function changeProvince(proObj, cityObj)
{
var xmlhttp;
if(window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readystate==4)//判断是否是完成状态
{
if(xmlhttp.status==200)//判断是否执行成功
{
document.getElementById(cityObj).innerHTML=xmlhttp.responsetext;
}
}
};
xmlhttp.open("GET","GetData.aspx?type="+document.getElementById(proObj).value,true);
xmlhttp.send(null);
}
// JScript 文件
function initialize()
{
var xmlhttp;
if(window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readystate==4)//判断是否是完成状态
{
if(xmlhttp.status==200)//判断是否执行成功
{
document.getElementById("ProvinceTD").innerHTML=xmlhttp.responsetext;
}
}
};
xmlhttp.open("GET","GetData.aspx?type=Province",true);
xmlhttp.send(null);
}
function initializeType()
{
var xmlhttp;
if(window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readystate==4)//判断是否是完成状态
{
if(xmlhttp.status==200)//判断是否执行成功
{
document.getElementById("TypeTD").innerHTML=xmlhttp.responsetext;
document.getElementById("TypeTD").innerHTML=xmlhttp.responsetext;
}
}
};
xmlhttp.open("GET","GetData.aspx?type=ProductType",true);
xmlhttp.send(null);
}
function changeProvince(proObj, cityObj)
{
var xmlhttp;
if(window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readystate==4)//判断是否是完成状态
{
if(xmlhttp.status==200)//判断是否执行成功
{
document.getElementById(cityObj).innerHTML=xmlhttp.responsetext;
}
}
};
xmlhttp.open("GET","GetData.aspx?type="+document.getElementById(proObj).value,true);
xmlhttp.send(null);
}
GetData.aspx.cs
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
//是否接收参数
if (!string.IsNullOrEmpty(Request["type"])) {
switch (Request["type"]) {
//获取省份
case "Province":
if (Cache["Province"] == null)
{
List<XbDataLabelItem> ProvinceList = new List<XbDataLabelItem>();
List<string> SearchProv = new List<string>();
SearchProv.Add("ParentID='c02c099d-2098-41a3-99f4-23711aff5b88'");
ProvinceList = XbDataLabelBPM.SelectDataLabelItemList(SearchProv.ToArray(), "ChineseText,ID", "ChineseText", -1, 0, "ID");
StringBuilder SbProvince = new StringBuilder();
SbProvince.Append("<select name=\"SProvince\" id=\"SProvince\" onchange=\"changeProvince('SProvince','CityTD');\">");
SbProvince.Append("<option value=''>请选择省份</option>");
for (int i = 0; i < ProvinceList.Count; i++)
{
SbProvince.Append("<option value='" + ProvinceList[i].ID + "'>" + ProvinceList[i].ChineseText + "</option>");
}
SbProvince.Append("</select>");
Cache.Insert("Province", SbProvince.ToString(), null, DateTime.Now.AddMinutes(5), TimeSpan.Zero);
Response.Write(Cache["Province"].ToString());
//Response.Write(SbProvince.ToString());
}
else
{
Response.Write(Cache["Province"].ToString());
}
break;
//默认无返回
default:
//如果传入为GUID,刚返回下线数据,主要为省市二级联动服务
try
{
new Guid(Request["type"].ToString());
List<XbDataLabelItem> CityList = new List<XbDataLabelItem>();
List<string> SearchCity = new List<string>();
SearchCity.Add("ParentID='" + Request["type"].ToString() + "'");
CityList = XbDataLabelBPM.SelectDataLabelItemList(SearchCity.ToArray(), "ChineseText,ID", "ChineseText", -1, 0, "ID");
StringBuilder SbCity = new StringBuilder();
SbCity.Append("<select name=\"SCity\" id=\"SCity\">");
SbCity.Append("<option value=''>请选择城市</option>");
for (int i = 0; i < CityList.Count; i++) {
SbCity.Append("<option value='" + CityList[i].ID + "'>" + CityList[i].ChineseText + "</option>");
}
SbCity.Append("</select>");
Response.Write(SbCity.ToString());
}
catch { }
break;
}
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
//是否接收参数
if (!string.IsNullOrEmpty(Request["type"])) {
switch (Request["type"]) {
//获取省份
case "Province":
if (Cache["Province"] == null)
{
List<XbDataLabelItem> ProvinceList = new List<XbDataLabelItem>();
List<string> SearchProv = new List<string>();
SearchProv.Add("ParentID='c02c099d-2098-41a3-99f4-23711aff5b88'");
ProvinceList = XbDataLabelBPM.SelectDataLabelItemList(SearchProv.ToArray(), "ChineseText,ID", "ChineseText", -1, 0, "ID");
StringBuilder SbProvince = new StringBuilder();
SbProvince.Append("<select name=\"SProvince\" id=\"SProvince\" onchange=\"changeProvince('SProvince','CityTD');\">");
SbProvince.Append("<option value=''>请选择省份</option>");
for (int i = 0; i < ProvinceList.Count; i++)
{
SbProvince.Append("<option value='" + ProvinceList[i].ID + "'>" + ProvinceList[i].ChineseText + "</option>");
}
SbProvince.Append("</select>");
Cache.Insert("Province", SbProvince.ToString(), null, DateTime.Now.AddMinutes(5), TimeSpan.Zero);
Response.Write(Cache["Province"].ToString());
//Response.Write(SbProvince.ToString());
}
else
{
Response.Write(Cache["Province"].ToString());
}
break;
//默认无返回
default:
//如果传入为GUID,刚返回下线数据,主要为省市二级联动服务
try
{
new Guid(Request["type"].ToString());
List<XbDataLabelItem> CityList = new List<XbDataLabelItem>();
List<string> SearchCity = new List<string>();
SearchCity.Add("ParentID='" + Request["type"].ToString() + "'");
CityList = XbDataLabelBPM.SelectDataLabelItemList(SearchCity.ToArray(), "ChineseText,ID", "ChineseText", -1, 0, "ID");
StringBuilder SbCity = new StringBuilder();
SbCity.Append("<select name=\"SCity\" id=\"SCity\">");
SbCity.Append("<option value=''>请选择城市</option>");
for (int i = 0; i < CityList.Count; i++) {
SbCity.Append("<option value='" + CityList[i].ID + "'>" + CityList[i].ChineseText + "</option>");
}
SbCity.Append("</select>");
Response.Write(SbCity.ToString());
}
catch { }
break;
}
}
}
}