以下代码绝对可以使用,也可以实现多级菜单。。。。
<script language="javascript">
function load(state)
{
var drp2 = document.getelementbyid("dropdownlist2");
for(var i=0;i<=drp2.options.length-1;i++)
{
drp2.remove(i);
}
var ohttpreq = new activexobject("msxml2.xmlhttp"); //发送请求
var odoc = new activexobject("msxml2.domdocument"); //响应结果
var state=document.getelementbyid("dropdownlist1").value;
ohttpreq.open("post","webform2.aspx?state="+state, false);
ohttpreq.send("");
result = ohttpreq.responsetext;
odoc.loadxml(result);
// items = odoc.selectnodes("//city/table");
items = odoc.selectnodes("//address/table");
for (var item = items.nextnode();item;item = items.nextnode())
{
var city = item.selectsinglenode("//address").nodetypedvalue;
var newoption = document.createelement("option");
newoption.text = city;
newoption.value = city;
drp2.options.add(newoption);
}
}
</script>
============================
webform1.aspx
private void page_load(object sender, system.eventargs e)
{
// 在此处放置用户代码以初始化页面
if(!ispostback)
{
sqlconnection con = new sqlconnection("packet size=4096;user id=sa;data source=server;persist security info=false;initial catalog=pubs");
sqldataadapter da = new sqldataadapter("select state from authors group by state",con);
dataset ds = new dataset("state");
da.fill(ds);
this.dropdownlist1.datasource = ds.tables[0];
this.dropdownlist1.datatextfield = "state";
this.dropdownlist1.datavaluefield = "state";
this.dropdownlist1.databind();
this.dropdownlist1.attributes.add("onchange","load()");
//dropdownlist1.
}
}
webform2.aspx
private void page_load(object sender, system.eventargs e)
{
// 在此处放置用户代码以初始化页面
if(this.request["state"]!=null)
{
string state = this.request["state"].tostring();
sqlconnection con = new sqlconnection("packet size=4096;user id=sa;data source=server;persist security info=false;initial catalog=pubs");
sqldataadapter da = new sqldataadapter("select address from authors where state = '"+state+"'",con);
dataset ds = new dataset("address");
da.fill(ds);
xmltextwriter writer = new xmltextwriter(response.outputstream, response.contentencoding);
writer.formatting = formatting.indented;
writer.indentation = 4;
writer.indentchar = ' ';
ds.writexml(writer);
writer.flush();
response.end();
writer.close();
}
}
新闻热点
疑难解答
图片精选