zoukankan
html css js c++ java
asp.net 2.0中用 ICallbackEventHandler 实现无刷新联动
vs2005beta2 中通过
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
Default2.aspx.cs
"
Inherits
=
"
Default2
"
%>
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
>
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
<
head
runat
="server"
>
<
title
>
Untitled Page
</
title
>
<
script
>
function
ClientCallback(result, context)
{
var
dropdown2
=
document.forms[
0
].elements['DropDownList2'];
dropdown2.innerHTML
=
""
;
var
rows
=
result.split('
|
');
alert(result.length);
for
(
var
i
=
0
; i
<
rows.length
-
1
;
++
i)
{
var
values
=
rows[i]
var
option
=
document.createElement(
"
OPTION
"
);
option.value
=
values;
option.innerHTML
=
values;
dropdown2.appendChild(option);
}
}
function
GetOrders(arg, context)
{
<%=
callBack
%>
;
}
</
script
>
</
head
>
<
body
>
<
form
id
="form1"
runat
="server"
>
<
div
>
<
asp:SqlDataSource
ID
="SqlDataSource1"
runat
="server"
ConnectionString
="<%$ ConnectionStrings:pubsConnectionString2 %>"
SelectCommand
="SELECT [au_id], [au_lname], [au_fname] FROM [authors]"
>
</
asp:SqlDataSource
>
<
asp:DropDownList
ID
="DropDownList1"
runat
="server"
>
</
asp:DropDownList
>
<
asp:DropDownList
ID
="DropDownList2"
runat
="server"
>
</
asp:DropDownList
></
div
>
</
form
>
</
body
>
</
html
>
using
System;
using
System.Data;
using
System.Configuration;
using
System.Collections;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.Data.SqlClient;
public
partial
class
Default2 : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(
!
this
.IsPostBack)
{
this
.DropDownList1.DataSource
=
this
.SqlDataSource1;
this
.DropDownList1.DataTextField
=
"
au_lname
"
;
this
.DropDownList1.DataValueField
=
"
au_id
"
;
this
.DropDownList1.DataBind();
this
.DropDownList1.Attributes.Add(
"
onchange
"
,
"
GetOrders(this.options[this.selectedIndex].value,'bbbbb');
"
);
}
}
protected
String callBack
{
get
{
return
this
.ClientScript.GetCallbackEventReference(
this
,
"
arg
"
,
"
ClientCallback
"
,
"
context
"
);
}
}
public
string
RaiseCallbackEvent(
string
eventArgument)
{
DataSet ds
=
new
DataSet();
SqlConnection cnn
=
new
SqlConnection (
"
Data Source=JKDL-PORTAL;Initial Catalog=pubs;Persist Security Info=True;User ID=sa;Password=111
"
);
SqlDataAdapter da
=
new
SqlDataAdapter(
"
select titles.title_id,title from titles inner join titleauthor on titleauthor.title_id = titles.title_id where au_id = '
"
+
eventArgument
+
"
'
"
, cnn);
cnn.Open ();
da.Fill(ds);
System.Text.StringBuilder str
=
new
System.Text.StringBuilder();
foreach
(DataRow dr
in
ds.Tables[
0
].Rows)
{
str.Append(dr[
"
title
"
]);
str.Append(
"
|
"
);
}
return
str.ToString ();
}
}
呵..... 越来越好了....
参考
http://www.extremeexperts.com/Net/Articles/ClientCallbacksinASPNETWhidbey.aspx
查看全文
相关阅读:
使用IDEA新建Maven项目没有完整的项目结构(src文件夹等等)
MyBatis:SQL语句中的foreach标签的详细介绍
嵌入式tomcat例子
springboot项目创建(myeclipse2017)
使用javafxpackager将java项目打包成exe
Spring Boot异常
myeclipse设置新建菜单file-new选项
myeclilpse打开文件所在位置的图标消失后的找回方法
mybatis使用接口方式报错
SSH中的Dao类继承HibernateDaoSupport后出现异常
原文地址:https://www.cnblogs.com/gwazy/p/207480.html
最新文章
JavaBean之我的理解
Eclipse常用快捷键[不断完善]
字节流文件拷贝工具类
统计字符串每个字符出现的次数
Map集合遍历的两种方式
集合去重复引入排序思想
集合元素去重复contains()方法使用
int[]数组指定位置添加元素
字符串数组通过集合遍历
字符串进行排序
热门文章
分割符(split)
判断年龄分割
Linux下安装Mysql出现的常见问题以及解决办法
java.net.SocketException: recvfrom failed: EBADF (Bad file descriptor)
解决IDEA2018.1.5或者Android Studio 3.0版本的输入法不跟随光标问题
Error: could not find java.dll 解决办法
Android使用adb命令查看CPU信息
Nginx出现500错误解决办法
Android 开发中Service完全解析
intellij idea导入不了java.util.Date解决办法
Copyright © 2011-2022 走看看