惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Security Archives - TechRepublic
Security Archives - TechRepublic
D
Docker
D
DataBreaches.Net
V
Vulnerabilities – Threatpost
P
Palo Alto Networks Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
L
LINUX DO - 热门话题
T
The Blog of Author Tim Ferriss
雷峰网
雷峰网
Project Zero
Project Zero
T
Threatpost
D
Darknet – Hacking Tools, Hacker News & Cyber Security
宝玉的分享
宝玉的分享
Stack Overflow Blog
Stack Overflow Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Securelist
Cisco Talos Blog
Cisco Talos Blog
Google DeepMind News
Google DeepMind News
Scott Helme
Scott Helme
The Cloudflare Blog
Know Your Adversary
Know Your Adversary
T
Tor Project blog
博客园_首页
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
Security Latest
Security Latest
Cyberwarzone
Cyberwarzone
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
H
Help Net Security
Simon Willison's Weblog
Simon Willison's Weblog
阮一峰的网络日志
阮一峰的网络日志
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Proofpoint News Feed
AWS News Blog
AWS News Blog
The GitHub Blog
The GitHub Blog
P
Proofpoint News Feed
T
Troy Hunt's Blog
量子位
G
GRAHAM CLULEY
O
OpenAI News
Engineering at Meta
Engineering at Meta
博客园 - Franky
SecWiki News
SecWiki News
F
Fortinet All Blogs
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com

博客园 - LeeXiaoLiang

自己写的一个javascript下拉列表类 jquery1.5.1根据元素ID获取元素对象 jquery向.ashx文件post中文乱码问题的解决 【转】通过在RowDataBound事件中把行索引绑定到控件的CommandArgument,然后在RowCommand事件中取出 - LeeXiaoLiang - 博客园 【转】GridView的RowCommand事件中取得行索引 - LeeXiaoLiang - 博客园 ASP.NET之GridView数据绑定 - LeeXiaoLiang - 博客园 希尔排序的C语言实现(2) 希尔排序的C语言实现(1) 简单插入排序的C语言实现 堆排序的C语言实现 对于堆排序算法的理解 【转】sqlserver中分页方法集锦 【转】高效的MySQL分页 【摘】完全二叉树 【原创】连接字符串数组 【摘】用C实现将数组转换为字符串 【原创】用C实现Trim()函数 - LeeXiaoLiang - 博客园 【转】浅谈数据库设计技巧 [转]数据库设计范式的理解
【转】GridView 实现服务器端和客户端全选的两种方法
LeeXiaoLiang · 2010-12-04 · via 博客园 - LeeXiaoLiang

代码很简单,这里就不累述了。看代码如下:

例子

C#

<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> // 计算数据,完全可以从数据看取得 ICollection CreateDataSource() { System.Data.DataTable dt = new System.Data.DataTable(); System.Data.DataRow dr; dt.Columns.Add(new System.Data.DataColumn("序号", typeof(System.String))); dt.Columns.Add(new System.Data.DataColumn("学生姓名", typeof(System.String))); dt.Columns.Add(new System.Data.DataColumn("语文", typeof(System.Decimal))); dt.Columns.Add(new System.Data.DataColumn("数学", typeof(System.Decimal))); dt.Columns.Add(new System.Data.DataColumn("英语", typeof(System.Decimal))); dt.Columns.Add(new System.Data.DataColumn("计算机", typeof(System.Decimal))); for (int i = 0; i < 8; i++) { System.Random rd = new System.Random(Environment.TickCount * i); ; dr = dt.NewRow(); dr[0] = i.ToString(); dr[1] = "【孟子E章】" + i.ToString(); dr[2] = System.Math.Round(rd.NextDouble() * 100, 2); dr[3] = System.Math.Round(rd.NextDouble() * 100, 2); dr[4] = System.Math.Round(rd.NextDouble() * 100, 2); dr[5] = System.Math.Round(rd.NextDouble() * 100, 2); dt.Rows.Add(dr); } System.Data.DataView dv = new System.Data.DataView(dt); return dv; } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GridView2.DataSource = GridView1.DataSource = CreateDataSource(); GridView2.DataBind(); GridView1.DataBind(); } } protected void Button1_Click(object sender, EventArgs e) { Ret1.Text = ""; foreach (GridViewRow gvr in GridView1.Rows) { CheckBox ch = (CheckBox)gvr.FindControl("ItemCheckBox"); if (ch.Checked) { Ret1.Text += "<li>GridView1 您选择的是(键值):" + GridView1.DataKeys[gvr.DataItemIndex].Value.ToString(); } } } protected void Button2_Click(object sender, EventArgs e) { Ret2.Text = ""; foreach (GridViewRow gvr in GridView2.Rows) { CheckBox ch = (CheckBox)gvr.FindControl("ItemCheckBox"); if (ch.Checked) { Ret2.Text += "<li>GridView2 您选择的是(键值):" + GridView2.DataKeys[gvr.DataItemIndex].Value.ToString(); } } } protected void CheckAll(object sender, EventArgs e) { CheckBox cbx = (CheckBox)sender; foreach (GridViewRow gvr in GridView1.Rows) { CheckBox ch = (CheckBox)gvr.FindControl("ItemCheckBox"); ch.Checked = cbx.Checked; } } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>GridView 实现服务器端和客户端全选的两种方法</title> <script type="text/javascript"> //<![CDATA[ function CheckAll(oCheckbox) { var GridView2 = document.getElementById("<%=GridView2.ClientID %>"); for(i = 1;i < GridView2.rows.length; i++) { GridView2.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked = oCheckbox.checked; } } //]]> </script> </head> <body> <form id="Form1" runat="server"> <table style="width:800px;font-size:12px;"> <tr valign="top"> <td> <asp:GridView ID="GridView1" runat="server" Font-Size="12px" BackColor="#FFFFFF" GridLines="Both" CellPadding="4" DataKeyNames="序号" AutoGenerateColumns="false"> <headerstyle backcolor="#EDEDED" height="26px" /> <columns> <asp:TemplateField> <headertemplate> <asp:CheckBox ID="CheckBox1" runat="server" Text="全选" AutoPostBack="true" OnCheckedChanged="CheckAll" /> </headertemplate> <itemtemplate> <asp:CheckBox ID="ItemCheckBox" runat="server" /> </itemtemplate> </asp:TemplateField> <asp:BoundField datafield="学生姓名" headertext="学生姓名" /> <asp:BoundField datafield="语文" headertext="语文" /> <asp:BoundField datafield="数学" headertext="数学" /> <asp:BoundField datafield="英语" headertext="英语" /> <asp:BoundField datafield="计算机" headertext="计算机" /> </columns> </asp:GridView> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="得到选择的行值" /> </td> <td align="right"> <asp:GridView ID="GridView2" runat="server" Font-Size="12px" BackColor="#FFFFFF" GridLines="Both" CellPadding="4" DataKeyNames="序号" AutoGenerateColumns="false"> <headerstyle backcolor="#EDEDED" height="26px" /> <columns> <asp:TemplateField> <headertemplate> <input id="Checkbox2" type="checkbox" onclick="CheckAll(this)" runat="server" /><label>全选</label> </headertemplate> <itemtemplate> <asp:CheckBox ID="ItemCheckBox" runat="server" /> </itemtemplate> </asp:TemplateField> <asp:BoundField datafield="学生姓名" headertext="学生姓名" /> <asp:BoundField datafield="语文" headertext="语文" /> <asp:BoundField datafield="数学" headertext="数学" /> <asp:BoundField datafield="英语" headertext="英语" /> <asp:BoundField datafield="计算机" headertext="计算机" /> </columns> </asp:GridView> <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="得到选择的行值" /> </td> </tr> <tr valign="top"> <td> <asp:Literal ID="Ret1" runat="server"></asp:Literal> </td> <td align="right"> <asp:Literal ID="Ret2" runat="server"></asp:Literal> </td> </tr> </table> </form> </body> </html>

posted on 2010-12-04 20:17  LeeXiaoLiang  阅读(183)  评论()    收藏  举报