会员
周边
众包
新闻
博问
闪存
赞助商
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
失落空间
博客园
首页
新随笔
联系
订阅
管理
GridView單頁全選--客戶段實現
<%
@ Page Language
=
"
C#
"
%>
<!
DOCTYPE html PUBLIC
"
-//W3C//DTD XHTML 1.0 Transitional//EN
"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
"
>
<
script runat
=
"
server
"
>
protected
void
Page_Load(
object
sender, EventArgs e)
...
{
if
(
!
IsPostBack)
...
{
MVC_M.MODEL a
=
new
MVC_M.MODEL();
string
[] strParams
=
null
;
object
[] objValues
=
null
;
a.Connstring
=
@"
Server=johnsqlexpress;uid=sa;pwd=;database=test;
"
;
GridView1.DataSource
=
a.GetData(
"
proc_select
"
, strParams, objValues);
GridView1.DataBind();
}
}
protected
void
Button1_Click(
object
sender, EventArgs e)
...
{
Label2.Text
=
""
;
foreach
(GridViewRow gvr
in
GridView1.Rows)
...
{
CheckBox ch
=
(CheckBox)gvr.FindControl(
"
CheckBox1
"
);
if
(ch.Checked)
...
{
Label2.Text
+=
"
<li>GridView1 您选择的是:
"
+
GridView1.DataKeys[gvr.DataItemIndex].Value.ToString();
}
}
}
</
script
>
<
html xmlns
=
"
http://www.w3.org/1999/xhtml
"
>
<
head runat
=
"
server
"
>
<
title
>
GridView單頁全選
--
客戶段實現
</
title
>
<
script language
=
"
javascript
"
type
=
"
text/javascript
"
>
//
<!CDATA[
function CheckAll(oCheckbox)
...
{
var GridView2
=
document.getElementById(
"
<%=GridView1.ClientID %>
"
);
for
(i
=
1
;i
<
GridView2.rows.length; i
++
)
...
{
GridView2.rows[i].cells[
0
].getElementsByTagName(
"
input
"
)[
0
].
checked
=
oCheckbox.
checked
;
//
GridView2.rows[i].cells[0].getElementsByTagName("input")[0].checked = document.getElementById("Checkbox2").checked;
}
}
//
]]>
</
script
>
</
head
>
<
body
>
<
form id
=
"
form1
"
runat
=
"
server
"
>
<
div
>
<
asp:GridView ID
=
"
GridView1
"
runat
=
"
server
"
BackColor
=
"
White
"
BorderColor
=
"
#3366CC
"
BorderStyle
=
"
None
"
BorderWidth
=
"
1px
"
CellPadding
=
"
4
"
DataKeyNames
=
"
TID,TName
"
>
<
FooterStyle BackColor
=
"
#99CCCC
"
ForeColor
=
"
#003399
"
/>
<
Columns
>
<
asp:TemplateField
>
<
HeaderTemplate
>
<
input id
=
"
Checkbox2
"
type
=
"
checkbox
"
onclick
=
"
return CheckAll(this)
"
/>
<
asp:Label ID
=
"
Label1
"
runat
=
"
server
"
Text
=
"
全選
"
></
asp:Label
>
</
HeaderTemplate
>
<
ItemTemplate
>
<
asp:CheckBox ID
=
"
CheckBox1
"
runat
=
"
server
"
Text
=
"
選擇
"
/>
</
ItemTemplate
>
</
asp:TemplateField
>
</
Columns
>
<
RowStyle BackColor
=
"
White
"
ForeColor
=
"
#003399
"
/>
<
SelectedRowStyle BackColor
=
"
#009999
"
Font
-
Bold
=
"
True
"
ForeColor
=
"
#CCFF99
"
/>
<
PagerStyle BackColor
=
"
#99CCCC
"
ForeColor
=
"
#003399
"
HorizontalAlign
=
"
Left
"
/>
<
HeaderStyle BackColor
=
"
#003399
"
Font
-
Bold
=
"
True
"
ForeColor
=
"
#CCCCFF
"
/>
</
asp:GridView
>
<
asp:Button ID
=
"
Button1
"
runat
=
"
server
"
OnClick
=
"
Button1_Click
"
Text
=
"
Button
"
/><
br
/>
<
asp:Label ID
=
"
Label2
"
runat
=
"
server
"
Text
=
"
Label
"
></
asp:Label
>&
nbsp;
</
div
>
</
form
>
</
body
>
</
html
>
posted on
2007-07-19 11:14
wkjs
阅读(
132
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部