GridView中CheckBox翻页记住选项
<asp:GridView ID="gvYwAssign" runat="server" AutoGenerateColumns="False"
AllowPaging="True" OnPageIndexChanging="gvYwAssign_PageIndexChanging"
DataSourceID="ObjectDs" OnRowDataBound="gvYwAssign_RowDataBound" PageSize="5">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="ckbSelAll" runat="server" Text="全选" OnCheckedChanged="cbSelAll_CheckedChanged" AutoPostBack="true" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="ckbxSel" runat="server" ToolTip='<%#Eval("id") %>' OnCheckedChanged="ckbxSel_CheckedChanged" AutoPostBack="true" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
--代码页
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2JinE : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string[] strallItems = new string[] { };
ViewState["allItems"] = strallItems;
}
}
//单个选中与取消
protected void ckbxSel_CheckedChanged(object sender, EventArgs e)
{
string[] strSelectFen = (string[])ViewState["allItems"];
List<string> listSelect = strSelectFen.ToList();
CheckBox chk = (CheckBox)sender;
DataControlFieldCell dcf = (DataControlFieldCell)chk.Parent; //这个对象的父类为cell
GridViewRow gr = (GridViewRow)dcf.Parent; //cell的父类就是row,这样就得到了该checkbox所在的该行
string nowId = chk.ToolTip;
if (true == chk.Checked)
{
if (false == listSelect.Contains(nowId))
{
listSelect.Add(nowId);
}
}
else
{
if (true == listSelect.Contains(nowId))
{
listSelect.Remove(nowId);
}
}
strSelectFen = listSelect.ToArray();
ViewState["allItems"] = strSelectFen;
}
//全选与取消
protected void cbSelAll_CheckedChanged(object sender, EventArgs e)
{
string[] strSelectFen = (string[])ViewState["allItems"];
List<string> listSelect = strSelectFen.ToList();
string nowId;
CheckBox cb1 = gvYwAssign.HeaderRow.FindControl("ckbSelAll") as CheckBox;
if (cb1.Checked)//选中
{
for (int i = 0; i < gvYwAssign.Rows.Count; i++)
{
CheckBox cb2 = gvYwAssign.Rows[i].FindControl("ckbxSel") as CheckBox;
cb2.Checked = true;
nowId = cb2.ToolTip;
if (false == listSelect.Contains(nowId))
{
listSelect.Add(nowId);
}
}
}
else//取消
{
for (int i = 0; i < gvYwAssign.Rows.Count; i++)
{
CheckBox cb2 = gvYwAssign.Rows[i].FindControl("ckbxSel") as CheckBox;
cb2.Checked = false;
nowId = cb2.ToolTip;
listSelect.Remove(nowId);
}
}
strSelectFen = listSelect.ToArray();
ViewState["allItems"] = strSelectFen;
}
//包括绑定原来选项
protected void gvYwAssign_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//绑定原来选项
string[] strSelectFen = (string[])ViewState["allItems"];
CheckBox chk = e.Row.FindControl("ckbxSel") as CheckBox;
string nowId = chk.ToolTip;
for (int j = 0; j < strSelectFen.Length; j++)
{
if (nowId == strSelectFen[j])
{
chk.Checked = true;
}
}
}
}
}
GridView中CheckBox翻页记住选项的更多相关文章
- Dynamics CRM2013 sub grid中数据翻页问题
CRM2013中一个很低级很令人无语的BUG,见下图subgrid中的明细条目超过当前页设置的条目后会有翻页,在底下有个paging bar会显示条数.页数.当前所处页数 但sp1版本的CRM打上ur ...
- asp.net,根据gridview 中checkbox复选框选中的行对数据库进行操作
在asp.net中,使用checkbox,对gridview添加复选框. 多选数据行后,根据已选数据,对原数据进行多条语句查询. string sql = "Select * from 表 ...
- GridView中CheckBox单击事件(oncheckedchanged)
在GridView中加入 CheckBox控件,想通过单击选中出现如下图所示效果: 具体做法是: 前台GV部份省掉.只加关键的CheckBox部份. view plaincopy to clipboa ...
- GridView中CheckBox的用法
以下是我在GridView中控制CheckBox的全选/取消全选,根据子CheckBox处理全选CheckBox状态的操作并获取所选GridView中所选行的列的值. 脚本代码: <scr ...
- Linux的vim编辑器中的翻页命令
当我们进入Linux的vim编辑器查看脚本时,按上下键查看是不是非常慢?这个时候就要用到我们的翻页快捷键了,快捷键命令如: 整页翻页命令为:Ctrl + f 键 f 的英文全拼为:forward: ...
- centos中less翻页查询的用法
用法实例: cat 21342.log | less
- 模板列传值到子窗体中,子窗体中多选gridview中checkbox保存数据多项到数据库中
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> &l ...
- js gridview中checkbox的全选与全不选
1.html: <asp:GridView runat="server" ID="gvAddBySR" AutoGenerateColumns=" ...
- bootStrap中的翻页效果
<div class="container"> <br/> <ul class="pagination"> <li&g ...
随机推荐
- newCachedThreadPool使用案例
newCachedThreadPool 缓存默认60s 猜下你的结果 package com.juc.threadpool; import java.util.concurrent.ExecutorS ...
- MOBA项目定点数的一个想法
能不能这样: 写逻辑时全用整数,不用每用到一个浮点数就要转一下成浮点数. 主要是除法 题细节较多,待思考
- shell命令中用source 和sh(或者bash)执行脚本的区别,以及export的作用
用户登录到Linux系统后,系统将启动一个用户shell,我们暂且称这个shell为shell父. 在这个shell父中,可以使用shell命令或声明变量,也可以创建并运行shell脚本程序. 当使用 ...
- unity 脚本说明
MonoBehavour void OnEnable(){ //OnEnable执行在Wake和之前 } void Awake(){ // } void Start(){ } void OnEnabl ...
- American Football Vocabulary!
American Football Vocabulary! Share Tweet Share You’ll learn all about the vocabulary of American fo ...
- 【386】operator 的 itemgetter、slice、and_、or_
itemgetter 用来获取数组中指定索引的元素 from operator import itemgetter itemgetter(1, 3, 5)('ABCDEFG') output: ('B ...
- node-sass:npm install node-sass --save
从git上拉下来的项目,要先安装依赖, 再运行. 缺少node-sass:npm install node-sass --save
- Spring3.0学习1.2(使用annotation)
使用annotation 首先 xml文件更改 新加xslt <?xml version="1.0" encoding="UTF-8"?> < ...
- Hibernate学习笔记3.1(Hibernate关系映射)
主要指对象之间的关系 1.一对一关联 一对一单项外键关联 比如说一夫一妻 Wifi.java package com.bjsxt.hibernate; import javax.persistence ...
- freemarker取数
在后端map必须的键值必须是字符串 java.util.Map busVoltagesMap = new java.util.HashMap(); busVoltagesMap.put("1 ...