三级无刷新联动(支持IE,Firefox)
aspx:
Code
<asp:DropDownList ID="ddlconames" runat="server" AppendDataBoundItems="True">
<asp:ListItem Value="">请选择厂别</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="ddlconames"
Display="Dynamic" ErrorMessage="请选择厂别"/>
<asp:DropDownList ID="ddldept" runat="server" Enabled="false">
<asp:ListItem Value="">请选择部门</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ControlToValidate="ddldept"
Display="Dynamic" ErrorMessage="请选择部门"/>
<asp:DropDownList ID="ddluserid" runat="server" Enabled="false">
<asp:ListItem Value="">请选择用户</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="ddluserid"
Display="Dynamic" ErrorMessage="请选择用户"/>
<asp:DropDownList ID="ddlconames" runat="server" AppendDataBoundItems="True">
<asp:ListItem Value="">请选择厂别</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="ddlconames"
Display="Dynamic" ErrorMessage="请选择厂别"/>
<asp:DropDownList ID="ddldept" runat="server" Enabled="false">
<asp:ListItem Value="">请选择部门</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ControlToValidate="ddldept"
Display="Dynamic" ErrorMessage="请选择部门"/>
<asp:DropDownList ID="ddluserid" runat="server" Enabled="false">
<asp:ListItem Value="">请选择用户</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="ddluserid"
Display="Dynamic" ErrorMessage="请选择用户"/>
Javascript:
Code
<script language="javascript" type="text/javascript">
function jb()
{
var A=null;
try
{
A=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
A=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(oc)
{
A=null
}
}
if ( !A && typeof XMLHttpRequest != "undefined" )
{
A=new XMLHttpRequest()
}
return A
}
function XmlPostTDept(obj)
{
var svalue = obj;
var weburl = "?conameid="+svalue;
var xmlhttp = jb();
xmlhttp.open("get",weburl,true);
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
{
var result = xmlhttp.responseText;
document.getElementById("ddldept").length = 0;
document.getElementById("ddldept").options.add(new Option("请选择部门",""));
document.getElementById("ddldept").disabled=false;
document.getElementById("ddluserid").length = 0;
document.getElementById("ddluserid").options.add(new Option("请选择用户",""));
document.getElementById("ddluserid").disabled=true;
if(result!="")
{
var allArray = result.split(",");
for(var i=0;i<allArray.length;i++)
{
var thisArray = allArray[i].split(";");
document.getElementById("ddldept").options.add(new Option(thisArray[1].toString(),thisArray[0].toString()));
}
}
}
}
xmlhttp.send(null);
}
function XmlPostTUser(obj)
{
var obj1=document.getElementById("ddlconames").value;
var weburluser="test.aspx?deptid="+obj+"&conameid="+obj1+"";
var xmlhttpuser = jb();
xmlhttpuser.open("get",weburluser,true);
xmlhttpuser.onreadystatechange=function()
{
if(xmlhttpuser.readyState==4)
{
var resultuser = xmlhttpuser.responseText;
document.getElementById("ddluserid").length = 0;
document.getElementById("ddluserid").options.add(new Option("请选择用户",""));
document.getElementById("ddluserid").disabled=false;
if(resultuser!="")
{
var allArray = resultuser.split(",");
for(var i=0;i<allArray.length;i++)
{
var thisArray = allArray[i].split(";");
document.getElementById("ddluserid").options.add(new Option(thisArray[1].toString(),thisArray[0].toString()));
}
}
}
}
xmlhttpuser.send(null);
}
</script>
<script language="javascript" type="text/javascript">
function jb()
{
var A=null;
try
{
A=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
A=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(oc)
{
A=null
}
}
if ( !A && typeof XMLHttpRequest != "undefined" )
{
A=new XMLHttpRequest()
}
return A
}
function XmlPostTDept(obj)
{
var svalue = obj;
var weburl = "?conameid="+svalue;
var xmlhttp = jb();
xmlhttp.open("get",weburl,true);
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
{
var result = xmlhttp.responseText;
document.getElementById("ddldept").length = 0;
document.getElementById("ddldept").options.add(new Option("请选择部门",""));
document.getElementById("ddldept").disabled=false;
document.getElementById("ddluserid").length = 0;
document.getElementById("ddluserid").options.add(new Option("请选择用户",""));
document.getElementById("ddluserid").disabled=true;
if(result!="")
{
var allArray = result.split(",");
for(var i=0;i<allArray.length;i++)
{
var thisArray = allArray[i].split(";");
document.getElementById("ddldept").options.add(new Option(thisArray[1].toString(),thisArray[0].toString()));
}
}
}
}
xmlhttp.send(null);
}
function XmlPostTUser(obj)
{
var obj1=document.getElementById("ddlconames").value;
var weburluser="test.aspx?deptid="+obj+"&conameid="+obj1+"";
var xmlhttpuser = jb();
xmlhttpuser.open("get",weburluser,true);
xmlhttpuser.onreadystatechange=function()
{
if(xmlhttpuser.readyState==4)
{
var resultuser = xmlhttpuser.responseText;
document.getElementById("ddluserid").length = 0;
document.getElementById("ddluserid").options.add(new Option("请选择用户",""));
document.getElementById("ddluserid").disabled=false;
if(resultuser!="")
{
var allArray = resultuser.split(",");
for(var i=0;i<allArray.length;i++)
{
var thisArray = allArray[i].split(";");
document.getElementById("ddluserid").options.add(new Option(thisArray[1].toString(),thisArray[0].toString()));
}
}
}
}
xmlhttpuser.send(null);
}
</script>
CS:
Code
if (!IsPostBack)
{
this.ddlconames.Attributes.Add("onchange", "XmlPostTDept(this.value)");
this.ddldept.Attributes.Add("onchange", "XmlPostTUser(this.value)");
}
private void DeptBind(string strconid)
{
PcManage.BLL.UserInfor uf = new PcManage.BLL.UserInfor();
DataTable dt = uf.ListConDept(strconid);
string mystr = "";
if (dt.Rows.Count != 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
mystr += "," + dt.Rows[i][0].ToString() + ";" + dt.Rows[i][1].ToString();
}
mystr = mystr.Substring(1);
}
Response.Write(mystr);
Response.End();
}
private void UserBind(string strconid, string strdeptid)
{
PcManage.BLL.UserInfor uf = new PcManage.BLL.UserInfor();
DataTable dt = uf.ListConDeptUsers(strconid, strdeptid);
string mystr2 = "";
if (dt.Rows.Count != 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
mystr2 += "," + dt.Rows[i][0].ToString() + ";" + dt.Rows[i][1].ToString();
}
mystr2 = mystr2.Substring(1);
}
Response.Write(mystr2);
Response.End();
}
if (!IsPostBack)
{
this.ddlconames.Attributes.Add("onchange", "XmlPostTDept(this.value)");
this.ddldept.Attributes.Add("onchange", "XmlPostTUser(this.value)");
}
private void DeptBind(string strconid)
{
PcManage.BLL.UserInfor uf = new PcManage.BLL.UserInfor();
DataTable dt = uf.ListConDept(strconid);
string mystr = "";
if (dt.Rows.Count != 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
mystr += "," + dt.Rows[i][0].ToString() + ";" + dt.Rows[i][1].ToString();
}
mystr = mystr.Substring(1);
}
Response.Write(mystr);
Response.End();
}
private void UserBind(string strconid, string strdeptid)
{
PcManage.BLL.UserInfor uf = new PcManage.BLL.UserInfor();
DataTable dt = uf.ListConDeptUsers(strconid, strdeptid);
string mystr2 = "";
if (dt.Rows.Count != 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
mystr2 += "," + dt.Rows[i][0].ToString() + ";" + dt.Rows[i][1].ToString();
}
mystr2 = mystr2.Substring(1);
}
Response.Write(mystr2);
Response.End();
}
效果图如下:
不过还有点问题,本页中不能进行多参数传递,搞得好郁闷,等解决了这个问题在更新。