三级无刷新联动(支持IE,Firefox)

aspx:

ContractedBlock.gif ExpandedBlockStart.gif 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="请选择用户"/>

Javascript:

ContractedBlock.gif ExpandedBlockStart.gif 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 ( !&& 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:

ContractedBlock.gif ExpandedBlockStart.gif 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();
        }

效果图如下:

不过还有点问题,本页中不能进行多参数传递,搞得好郁闷,等解决了这个问题在更新。

转载于:https://www.cnblogs.com/cnaspnet/archive/2008/08/22/1274117.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值