省市县三级联动Word下载.docx
- 文档编号:22094404
- 上传时间:2023-02-02
- 格式:DOCX
- 页数:17
- 大小:19.23KB
省市县三级联动Word下载.docx
《省市县三级联动Word下载.docx》由会员分享,可在线阅读,更多相关《省市县三级联动Word下载.docx(17页珍藏版)》请在冰豆网上搜索。
runat="
server"
Height="
20px"
Width="
60px"
Font-Size="
12px"
>
/asp:
DropDownList>
DropDownList2"
>
DropDownList3"
然后再添加三个Lable控件,这是为了接收dropdownlist控件中的值
inputid="
lbl_provice_id"
text"
style="
display:
none;
"
name="
/>
lbl_provice"
style="
DISPLAY:
none"
value="
lbl_city"
lbl_area"
然后再在页面的源码中的page中添加enableEventValidation="
false"
这样就可以解决回调会回调函数无效这个错误。
当然我们要在页面中调用js代码。
scripttype="
text/javascript"
src="
js/AdminLeaquerMessage.js"
/script>
上面是页面中要处理的工作。
我们在来看js代码
AdminLeaquerMessage.js代码:
functionCityResult(parent_id,objDropDownList){
//alert(parent_id.text);
//alert(document.getElementById("
).value);
document.getElementById("
).value=parent_id.text;
).value=parent_id.value;
SaLeaMessage.BindCity(parent_id.value,objDropDownList,get_City_Result_CallBack);
}
functionget_City_Result_CallBack(response)
{
if(response.value!
=null)
{
vards=response.value;
varfirst_city;
varfirst_city_id;
//绑定城市
if(ds!
=null&
&
typeof(ds)=="
object"
&
ds.Tables!
=null){
document.getElementById("
).length=0;
for(vari=0;
i<
ds.Tables[0].Rows.length;
i++){
varname=ds.Tables[0].Rows[i].Text;
varid=ds.Tables[0].Rows[i].Value;
if(i==0){first_city=name;
first_city_id=id};
document.getElementById("
).options.add(newOption(name,id));
}
//每次省选择以后,赋省下第一个城市值
document.getElementById("
).innerText=first_city;
//绑定地区
if(first_city_id&
typeof(first_city_id)!
='
undefined'
SaLeaMessage.BindArea(first_city_id,DropDownList3'
get_Area_Result_CallBack);
else{
document.getElementById("
}
}
functionAreaResult(parent_id,objDropDownList){
).innerText=parent_id.text;
SaLeaMessage.BindArea(parent_id.value,objDropDownList,get_Area_Result_CallBack);
functionget_Area_Result_CallBack(response)
varfirst_area;
varfirst_area_id;
if(i==0)
{
first_area=name;
first_area_id=id
};
document.all("
//每次城市后赋第一个地区值
).innerText=first_area;
functionAreaResultV(parent_id,objDropDownList){
C#代码:
在page_load中我们需要添加代码:
protectedvoidPage_Load(objectsender,EventArgse)
{
Ajax.Utility.RegisterTypeForAjax(typeof(Leaquer));
BindDropDownList();
#regionajax三级省市区联动xml
///<
summary>
///初始化绑定省级下拉框
/summary>
protectedvoidBindDropDownList()
XmlDocumentxmlDoc=newXmlDocument();
xmlDoc.Load(Server.MapPath("
xml/ChinaArea.xml"
));
XmlNodeListnodelist=xmlDoc.SelectNodes("
area/province[@provinceID]"
);
ListItemli=null;
foreach(XmlNodemyNodeinnodelist)
li=newListItem();
li.Value=myNode.Attributes["
provinceID"
].Value;
li.Text=myNode.Attributes["
province"
this.DropDownList1.Items.Add(li);
this.DropDownList1.SelectedIndex=15;
nodelist=xmlDoc.SelectNodes("
area/province[@provinceID=410000]/City"
CityID"
City"
this.DropDownList2.Items.Add(li);
this.DropDownList2.SelectedIndex=0;
area/province/City[@CityID=410100]/Piecearea"
PieceareaID"
Piecearea"
this.DropDownList3.Items.Add(li);
DropDownList1.Attributes.Add("
onchange"
"
CityResult(this.options[selectedIndex],'
DropDownList2'
)"
DropDownList2.Attributes.Add("
AreaResult(this.options[selectedIndex],'
DropDownList3'
DropDownList3.Attributes.Add("
AreaResultV(this.options[selectedIndex],'
//创建服务器端方法。
只要给一个方法加上[AjaxPro.AjaxMethod]标记,该方法就变成一个AjaxPro可进行映射调用的方法
[Ajax.AjaxMethod]
//该方法我们将实现从客户端传入一个参数,在服务器端进行查询后返回到客户端。
publicDataSetBindCity(stringparent_id,string_ddl)
//stringsqlstring=@"
selectcityIDasValue,cityasTextfromcitywherefather="
+parent_id;
//returnGetDS(sqlstring);
try
../xml/ChinaArea.xml"
catch(Exceptionex)
stringaa=ex.Message;
stringi="
;
area/province[@provinceID="
+parent_id+"
]/City"
DataTablemyDataTable=newDataTable();
DataColumnmyColumn;
DataRowmyRow;
stringValue="
Text="
myColumn=newDataColumn();
myColumn.DataType=System.Type.GetType("
System.String"
myColumn.ColumnName="
Value"
myDataTable.Columns.Add(myColumn);
myColumn.DataType=Type.GetType("
Text"
myRow=myDataTable.NewRow();
Value=myNode.Attributes["
Text=myNode.Attributes["
myRow["
]=Value;
]=Text;
myDataTable.Rows.Add(myRow);
DataSetds=newDataSet();
ds.Tables.Add(myDataTable);
returnds;
publicDataSetBindArea(stringchild_id,string_ddl)
selectareaIDasValue,areaasTextfromareawherefather="
+child_id;
area/province/City[@CityID="
+child_id+"
]/Piecearea"
#endregion
问题1:
好了以上代码就可以完成你的注册信息中的省市县三级联动或者说是查询中用到的三级联动
那么如果我们想修改用户信息时用到了三级联动,也就是说我们最开始是从数据库中读取数据页面中最开始要显示我们数据库中的省市县只有修改的时候才开始显示三级联动这时候我们要修改一下c#后台代码
#region绑定省市县
///绑定省市县
publicvoidBindDropDownList()
foreach(ListItemliiinDropDownList1.Items)
if(lii.Text==this.lbl_provice.Value)
+Convert.ToInt32(lii.Value)+"
DropDownList2.SelectedIndex=-1;
foreach(ListItemliiiinDropDownList2.Items)
if(liii.Text==this.lbl_city.Value)
liii.Selected=true;
+Convert.ToInt32(liii.Value)+"
DropDownList3.SelectedIndex=-1;
foreach(ListItemlistinDropDownList3.Items)
if(list.Text==this.lbl_area.Value)
list.Selected=true;
break;
///绑定市
paramname="
parent_id"
/param>
_ddl"
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 省市 三级 联动