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
查看全文
相关阅读:
02 make和目录结构
05 UCI
IE6下position:fixed不固定的解决办法
php内存溢出
MySQL计划任务(事件调度器)(Event Scheduler)
PHP面向对象
php学习笔记——12年2月16日开始不断更新
Phpnow下配置Xdebug调试
边学边用
ASP时间格式化函数
原文地址:https://www.cnblogs.com/winner/p/618563.html
最新文章
SharePoint 2010多语言UI,以及开发人员需要注意的
ASP.NET Security Vulnerability对SharePoint的影响
为SharePoint网站创建自定义导航菜单
在SharePoint 2010中使用QuickPart
在SharePoint 2010程序中使用Session
从“为什么不能直接打开PDF文件”说到“脚本攻击”
使用JSOM创建一个SharePoint网站计数器
关于SharePoint 2010 SP1
为SharePoint搜索创建自定义优化参数
如何解析SharePoint搜索中心网站的精简过滤参数(r参数)
热门文章
SharePoint 2010中的沙盒解决方案(Sandboxed Solution)
ECB菜单控制器(for SharePoint 2007)
10 基础网络知识
11 libubox
04 opkg
08 package分析
03 openwrt的启动过程
07 etc目录
06 config
09 diff patch quilt
Copyright © 2011-2022 走看看