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
查看全文
相关阅读:
HTTP与HTTPS的区别
Linux内核结构体--kfifo 环状缓冲区
POSIX 线程详解
linux的fork()函数-进程控制
HDU 3435 A new Graph Game(最小费用最大流)&HDU 3488
Memcached安装使用和源代码调试
结构-01. 有理数比較(10)
Android:你不知道的 WebView 使用漏洞
关于文件异步上传
<二代測序> 批量下载 NCBI sra 文件
原文地址:https://www.cnblogs.com/gwazy/p/207480.html
最新文章
ZH奶酪:PHP安装扩展imagick
ZH奶酪:PHP遍历目录/文件的3种方法
ZH奶酪:C语言中malloc()和free()函数解析
ZH奶酪:【数据结构与算法】并查集基础
ZH奶酪:【数据结构与算法】基础排序算法总结与Python实现
sppNet论文学习
R-CNN论文学习
Fast RCNN论文学习
Facebook libra开发者文档- 3 -Life of a Transaction交易生命周期
Facebook libra开发者文档- 2 -Libra Protocol: Key Concepts核心概念
热门文章
Facebook libra开发者文档- 1 -welcome
Facebook libra白皮书
目标检测中的选择性搜索-selective search-没弄
目标检测的各类评价指标是什么及其计算
Edge/Chrome/火狐/Safari/Opera和IE
Canvas简述
Linux面试题
Linux内存源码分析-内存池
TCP协议为什么会采用三次握手,若采用二次握手可以吗?
TCP三次握手和四次挥手协议
Copyright © 2011-2022 走看看