XmlHttp实现无刷新三联动ListBox

1.html
< HTML >
    
< HEAD >
        
< title > XmlHttp实现无刷新三联动ListBox </ title >
        
< meta  name ="GENERATOR"  Content ="Microsoft Visual Studio .NET 7.1" >
        
< meta  name ="CODE_LANGUAGE"  Content ="C#" >
        
< meta  name ="vs_defaultClientScript"  content ="JavaScript" >
        
< meta  name ="vs_targetSchema"  content ="http://schemas.microsoft.com/intellisense/ie5" >
        
< SCRIPT  LANGUAGE ="JavaScript" >
            
<!--
                
//以XML求取ListBox2的数据
                function XmlPost2(obj)
                
{
                  
var svalue = obj.value;
                  
var webFileUrl = "?povinceid=" + svalue;
                  
var result = "";
                  
var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
                  xmlHttp.open(
"POST", webFileUrl, false);
                  xmlHttp.send(
"");
                  result 
= xmlHttp.responseText;
                  
                  
if(result != "")
                  
{
                    document.all(
"ListBox2").length=0;
                    
var piArray = result.split(",");
                    
for(var i=0;i<piArray.length;i++)
                    
{
                      
var ary1 = piArray[i].toString().split("|");
                      document.all(
"ListBox2").options.add(new Option(ary1[1].toString(),ary1[0].toString()));
                    }

                  }

                  
else
                  
{
                    alert(result);
                  }

                }

                
//以XML求取ListBox3的数据
                function XmlPost3(obj)
                
{
                  
var svalue = obj.value;
                  
var webFileUrl = "?cityid=" + svalue;
                  
var result = "";
                  
var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
                  xmlHttp.open(
"POST", webFileUrl, false);
                  xmlHttp.send(
"");
                  result 
= xmlHttp.responseText;
                  
                  
if(result != "")
                  
{
                    document.all(
"ListBox3").length=0;
                    
var piArray = result.split(",");
                    
for(var i=0;i<piArray.length;i++)
                    
{
                      
var ary1 = piArray[i].toString().split("|");
                      document.all(
"ListBox3").options.add(new Option(ary1[1].toString(),ary1[0].toString()));
                    }

                  }

                  
else
                  
{
                    alert(result);
                  }

                }
                
            
//-->
        
</ SCRIPT >
    
</ HEAD >
    
< body  MS_POSITIONING ="GridLayout" >
        
< form  id ="Form1"  method ="post"  runat ="server" >
            
< asp:ListBox  id ="ListBox1"  style ="Z-INDEX: 101; LEFT: 24px; POSITION: absolute; TOP: 16px"  runat ="server"
                Height
="448px"  Width ="200px" ></ asp:ListBox >
            
< asp:ListBox  id ="ListBox2"  style ="Z-INDEX: 102; LEFT: 352px; POSITION: absolute; TOP: 24px"  runat ="server"
                Height
="432px"  Width ="168px" ></ asp:ListBox >
            
< asp:ListBox  id ="ListBox3"  style ="Z-INDEX: 103; LEFT: 568px; POSITION: absolute; TOP: 24px"  runat ="server"
                Height
="424px"  Width ="200px" ></ asp:ListBox >
        
</ form >
    
</ body >
</ HTML >
2.cs代码
public   class  WebForm2 : System.Web.UI.Page
    
{
        
protected System.Web.UI.WebControls.ListBox ListBox1;
        
protected System.Web.UI.WebControls.ListBox ListBox2;
        
protected System.Web.UI.WebControls.ListBox ListBox3;
    
        
public static string ConnectionString=System.Configuration .ConfigurationSettings .AppSettings["ConnectionString"];
    
        
GetDataSet

        
property

        
Page_Load

        
down2_bind

        
down3_bind
        
        
down1_bind

        
Web Form Designer generated code
    }
3.数据库下载 /Files/singlepine/area.rar
4.数据库脚本(3,4随便一个就可以)
if   exists  ( select   *   from  dbo.sysobjects  where  id  =   object_id (N ' [dbo].[area] ' and   OBJECTPROPERTY (id, N ' IsUserTable ' =   1 )
drop   table   [ dbo ] . [ area ]
GO

if   exists  ( select   *   from  dbo.sysobjects  where  id  =   object_id (N ' [dbo].[city] ' and   OBJECTPROPERTY (id, N ' IsUserTable ' =   1 )
drop   table   [ dbo ] . [ city ]
GO

if   exists  ( select   *   from  dbo.sysobjects  where  id  =   object_id (N ' [dbo].[povince] ' and   OBJECTPROPERTY (id, N ' IsUserTable ' =   1 )
drop   table   [ dbo ] . [ povince ]
GO

CREATE   TABLE   [ dbo ] . [ area ]  (
    
[ id ]   [ int ]   NOT   NULL  ,
    
[ areaID ]   [ nvarchar ]  ( 50 ) COLLATE Chinese_PRC_CI_AS  NULL  ,
    
[ area ]   [ nvarchar ]  ( 60 ) COLLATE Chinese_PRC_CI_AS  NULL  ,
    
[ father ]   [ nvarchar ]  ( 6 ) COLLATE Chinese_PRC_CI_AS  NULL  
ON   [ PRIMARY ]
GO

CREATE   TABLE   [ dbo ] . [ city ]  (
    
[ id ]   [ int ]   NOT   NULL  ,
    
[ cityID ]   [ nvarchar ]  ( 6 ) COLLATE Chinese_PRC_CI_AS  NULL  ,
    
[ city ]   [ nvarchar ]  ( 50 ) COLLATE Chinese_PRC_CI_AS  NULL  ,
    
[ father ]   [ nvarchar ]  ( 6 ) COLLATE Chinese_PRC_CI_AS  NULL  
ON   [ PRIMARY ]
GO

CREATE   TABLE   [ dbo ] . [ povince ]  (
    
[ id ]   [ int ]   NOT   NULL  ,
    
[ provinceID ]   [ nvarchar ]  ( 6 ) COLLATE Chinese_PRC_CI_AS  NULL  ,
    
[ province ]   [ nvarchar ]  ( 40 ) COLLATE Chinese_PRC_CI_AS  NULL  
ON   [ PRIMARY ]
GO
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值