日期:2014-05-18 浏览次数:20559 次
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>无标题页</title> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:DropDownList ID="list1" runat="server" AutoPostBack ="true" onselectedindexchanged="list1_SelectedIndexChanged"> </asp:DropDownList> <asp:DropDownList ID="list2" runat="server"> </asp:DropDownList> </ContentTemplate> <Triggers > <asp:AsyncPostBackTrigger ControlID ="list1" EventName ="SelectedIndexChanged" /> </Triggers> </asp:UpdatePanel> </div> </form> </body> </html>
------解决方案--------------------
发一个给你吧..
<SCRIPT LANGUAGE="JavaScript">
<!--
//以XML求取数据
//参数:
//obj,当前动作的下拉框
//fullName:要填充的下拉框
function XmlPost(obj,fullName)
{
//求取当前下拉框的值
var svalue = obj.value;
//定义要填充的对象
var fullObj = document.all(fullName);
//定义取值地址
var webFileUrl = "?sortid=" + svalue;
//定义返回值
var result = "";
//开始取值过程
var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
xmlHttp.open("POST", webFileUrl, false);
xmlHttp.send("");
result = xmlHttp.responseText;
//如果有取到值,则根据格式进行拆分
//注意如果选择了第一行"请选择"空行时,是取不到值的,因此多加了一个条件
if(result != "" && svalue != "")
{
//先清空原有的值
fullObj.length=0;
//拆分值成数组
var piArray = result.split(",");
//循环数组
for(var i=0;i <piArray.length;i++)
{
//再拆分成ID及名称
var ary1 = piArray[i].toString().split("|");
//逐一添加项
fullObj.options.add(new Option(ary1[1].toString(),ary1[0].toString()));
}
}
else
{
//如果没有取到值,则清空要填充的下拉框的值
fullObj.length = 0;
fullObj.options.add(new Option("请选择",""));
}
}
//-->
</SCRIPT>