zoukankan
html css js c++ java
XmlHttp实现无刷新三联动ListBox
<
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
#region
GetDataSet
public
static
DataSet GetDataSet(
string
sql)
{
SqlDataAdapter sda
=
new
SqlDataAdapter(sql,ConnectionString);
DataSet ds
=
new
DataSet();
sda.Fill(ds);
return
ds;
}
#endregion
property
#region
property
private
string
povinceid
{
get
{
if
(ViewState[
"
povinceid
"
]
!=
null
&&
ViewState[
"
povinceid
"
].ToString()
!=
""
)
{
return
ViewState[
"
povinceid
"
].ToString();
}
else
{
if
(Request[
"
povinceid
"
]
!=
null
&&
Request[
"
povinceid
"
].ToString()
!=
""
)
{
return
Request[
"
povinceid
"
];
}
else
{
return
""
;
}
}
}
set
{
ViewState[
"
povinceid
"
]
=
value;
}
}
private
string
cityid
{
get
{
if
(ViewState[
"
cityid
"
]
!=
null
&&
ViewState[
"
cityid
"
].ToString()
!=
""
)
{
return
ViewState[
"
cityid
"
].ToString();
}
else
{
if
(Request[
"
cityid
"
]
!=
null
&&
Request[
"
cityid
"
].ToString()
!=
""
)
{
return
Request[
"
cityid
"
];
}
else
{
return
""
;
}
}
}
set
{
ViewState[
"
povinceid
"
]
=
value;
}
}
#endregion
Page_Load
#region
Page_Load
private
void
Page_Load(
object
sender, System.EventArgs e)
{
if
(
!
this
.IsPostBack)
{
this
.down1_bind();
this
.ListBox1.Attributes.Add(
"
onchange
"
,
"
XmlPost2(this);
"
);
this
.ListBox2.Attributes.Add(
"
onchange
"
,
"
XmlPost3(this);
"
);
}
if
(povinceid
!=
""
)
{
this
.down2_bind(povinceid);
}
if
(cityid
!=
""
)
{
this
.down3_bind(cityid);
}
}
#endregion
down2_bind
#region
down2_bind
private
void
down2_bind(
string
id)
{
string
mystr
=
""
;
string
sql
=
"
select cityID,city from city where father = '
"
+
id
+
"
'
"
;
DataSet ds
=
GetDataSet(sql);
if
(ds.Tables[
0
].Rows.Count
!=
0
)
{
for
(
int
i
=
0
;i
<
ds.Tables[
0
].Rows.Count;i
++
)
{
mystr
+=
"
,
"
+
ds.Tables[
0
].Rows[i][
0
].ToString()
+
"
|
"
+
ds.Tables[
0
].Rows[i][
1
].ToString();
}
mystr
=
mystr.Substring(
1
);
}
this
.Response.Write(mystr);
this
.Response.End();
}
#endregion
down3_bind
#region
down3_bind
private
void
down3_bind(
string
id)
{
string
mystr
=
""
;
string
sql
=
"
select areaID,area from area where father = '
"
+
id
+
"
'
"
;
DataSet ds
=
GetDataSet(sql);
if
(ds.Tables[
0
].Rows.Count
!=
0
)
{
for
(
int
i
=
0
;i
<
ds.Tables[
0
].Rows.Count;i
++
)
{
mystr
+=
"
,
"
+
ds.Tables[
0
].Rows[i][
0
].ToString()
+
"
|
"
+
ds.Tables[
0
].Rows[i][
1
].ToString();
}
mystr
=
mystr.Substring(
1
);
}
this
.Response.Write(mystr);
this
.Response.End();
}
#endregion
down1_bind
#region
down1_bind
private
void
down1_bind()
{
string
sql
=
"
select provinceID,province from povince
"
;
DataSet ds
=
GetDataSet(sql);
this
.ListBox1.DataSource
=
ds;
this
.ListBox1.DataValueField
=
"
provinceID
"
;
this
.ListBox1.DataTextField
=
"
province
"
;
this
.ListBox1.DataBind();
}
#endregion
Web Form Designer generated code
#region
Web Form Designer generated code
override
protected
void
OnInit(EventArgs e)
{
//
//
CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base
.OnInit(e);
}
/**/
///
<summary>
///
Required method for Designer support - do not modify
///
the contents of this method with the code editor.
///
</summary>
private
void
InitializeComponent()
{
this
.Load
+=
new
System.EventHandler(
this
.Page_Load);
}
#endregion
}
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
查看全文
相关阅读:
多线程系列二:原子操作
多线程系列一:线程基础
java面试题——高级篇
SpringMVC系列(十六)Spring MVC与Struts2的对比
SpringMVC系列(十五)Spring MVC与Spring整合时实例被创建两次的解决方案以及Spring 的 IOC 容器和 SpringMVC 的 IOC 容器的关系
Android IOS WebRTC 音视频开发总结(三六)-- easyRTC介绍
Android IOS WebRTC 音视频开发总结(三五)-- chatroulette介绍
Android IOS WebRTC 音视频开发总结(三四)-- windows.20150706
Android IOS WebRTC 音视频开发总结(三三)-- Periscope介绍
Android IOS WebRTC 音视频开发总结(三二)-- WebRTC项目开发建议
原文地址:https://www.cnblogs.com/winner/p/618563.html
最新文章
jenkins构建的robot result结果不更新
RF实现多次失败重跑结果合并的基础方法和优化方法
hudson.AbortException: No files found in path D: estprojectproject2 estoutput with configured filemask: output.xml
RF失败案例重跑
执行RF设置顶层测试套件的描述说明
BIO、NIO、AIO系列一:NIO
Redis系列十:缓存雪崩、缓存穿透、缓存预热、缓存更新、缓存降级
多线程系列六:线程池
多线程系列五:并发工具类和并发容器
Redis系列九:redis集群高可用
热门文章
Redis系列八:redis主从复制和哨兵
Redis系列七:redis持久化
Redis系列六:redis相关功能
Redis系列五:redis键管理和redis数据库管理
Redis系列四:redis支持的数据类型
Redis系列三:reids常用命令
Redis系列二:reids介绍
Redis系列一:reids的单机版安装
多线程系列四:AQS-AbstractQueuedSynchronizer
多线程系列三:Lock和Condition
Copyright © 2011-2022 走看看