A.aspx页面放一个dropdownlist,在A.aspx.cs添加: this.drpSchool.Attributes.Add("onchange", "load(this.options[this.selectedIndex].value)");
在A.aspx页面添加如下脚本:
function load(state){
var oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");
var oDoc = new ActiveXObject("MSXML2.DOMDocument");
oHttpReq.open("POST", "../B.aspx?state="+state, false);
oHttpReq.send("");
result = oHttpReq.responseText;
oDoc.loadXML(result);
document.all("DropDownList2 ").length=0;//清空原来绑定的值
items1 = oDoc.selectNodes("//NewDataSet/Table/dtid");
items2 = oDoc.selectNodes("//NewDataSet/Table/dtname");
var itemsLength=items1.length;
for(i=0;i<itemsLength;i++)
//将小类的类名和编号赋予DropDownList2
{
var newOption = document.createElement("OPTION");
newOption.text=items2[i].text;
newOption.value=items1[i].text;
drp2.options.add(newOption);
// newOption.value=6;
}
}
B.aspx.cs页面:
if (Request.QueryString["state"] != null && Request.QueryString["state"].ToString() != "")
{
try
{
int shengNo = int.Parse(Request["state"].ToString());
// int shengNo = 1;
DataSet ds = new DataSet();
db dbb = new db();
ds = dbb.GetDataSet(SQL语句);
if (ds.Tables[0].Rows.Count > 0)
{
XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.IndentChar = ' ';
writer.WriteStartDocument();
ds.WriteXml(writer);
writer.Flush();
Response.End();
writer.Close();
}
}
catch { }
}