JS、Xml实现无限级无刷新联动

 

此方法的不足:牺性一个apsx页面输出xml代码
apsx页:
<script type="text/javascript">
function GetSmallType(bigID,smallID,url,xmlvalue,xmltext){
//(大类控件的ID,小类控件的ID,读取小类数据apsx页,读取xml的值,读取xml的显示)
var drp2 = document.getElementById(smallID);
drp2.innerText="";
for(var i = 0;i<=drp2.options.length -1;i++){
drp2.remove(i);
}
var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
var oDoc = new ActiveXObject("MSXML2.DOMDocument");
var state=document.getElementById(bigID).value;
xmlhttp.open("POST", url+state,false);
xmlhttp.send("");
var res=oDoc.loadXML(xmlhttp.responseText);
var naItems = oDoc.selectNodes(xmltext);
var idItems = oDoc.selectNodes(xmlvalue);
var item;
var id;
var newOption = document.createElement("OPTION");
newOption.text ="请岗位小类";
newOption.value = "";
drp2.options.add(newOption);
for (item = naItems.nextNode(),id=idItems.nextNode(); item&&id; item = naItems.nextNode(),id=idItems.nextNode()){
var nastr = item.nodeTypedValue;
var idstr = id.nodeTypedValue;
newOption = document.createElement("OPTION");
newOption.text =nastr;
newOption.value = idstr;
drp2.options.add(newOption);
}
}
</script>

<asp:DropDownList ID="DropDownList_StationBigType" runat="server">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList_StationSmallType" runat="server">
</asp:DropDownList>

CS页:
//初始化 岗位大类表。
String strSQL = "select [BigPKID],[BigType] from StationBigType";
object objStationBigType = ObjDB.DeleteAndGetBySql(strSQL, Globals.GetConnectionString(), false, "招聘岗位大类", ReturnType.DataSet);
if (objStationBigType.GetType().Name != "MessageBox")
{
DataSet ds = (DataSet)objStationBigType;
this.DropDownList_StationBigType.DataSource = ds;
this.DropDownList_StationBigType.DataTextField = "BigType";
this.DropDownList_StationBigType.DataValueField = "BigPKID";
this.DropDownList_StationBigType.DataBind();
this.DropDownList_StationBigType.SelectedValue = "1";
this.DropDownList_StationBigType.Attributes.Add("onchange", "GetSmallType('ctl00_ContentHolder_DropDownList_StationBigType','ctl00_ContentHolder_DropDownList_StationSmallType','../GetStationSmallType.aspx?id=','//StationSmallType/Table/SmallPKID','//StationSmallType/Table/SmallType')");
//GetSmallType(bigID,smallID,url,xmlvalue,xmltext)
//GetSmallType(大类控件的ID,小类控件的ID,读取小类数据apsx页,读取xml的值,读取xml的显示)
}
else
{
MessageBox eobjStationBigType = (MessageBox)objStationBigType;
Response.Write(eobjStationBigType.ErrMessage.ToString());
}
===================

牺牲的aspx页GetStationSmallType.aspx:
cs:
string id = this.Request["id"];
SqlConnection con = new SqlConnection(Globals.GetConnectionString());
SqlDataAdapter da = new SqlDataAdapter("select SmallPKID,SmallType from StationSmallType where BigPKID=@id order by SmallPKID", con);
da.SelectCommand.Parameters.Add("@id", id);
DataSet ds = new DataSet("StationSmallType");
da.Fill(ds);

ds.WriteXml(Response.OutputStream);
Response.Flush();
Response.End();
Response.Start();
Response.Write();
Response.Request.write();
GetSmallType(bigID,smallID,url,xmlvalue,xmltext);

 

你可能感兴趣的:(xml)