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 ...
随机推荐
- laravel视图$errors为空
最近用laravel5.2的validator时,完全参考手册操作,结果控制器$validator->errors()->all()正常显示错误信息,$validator->fail ...
- How to Pronounce the Months of the Year
How to Pronounce the Months of the Year Share Tweet Share Tagged With: Most Popular Some of the mont ...
- maven ,添加加密算法 apache commons-codec.jar 包
在百度搜索commons-codec.jar maven , http://mvnrepository.com/ 到 maven 库搜索 commons-codec.jar maven .你需要添加 ...
- Ubuntu下的LNMP环境
保证联网的情况下,直接参照http://lnmp.org/install.html进行安装,以下花括号内为原文引用: { 1.使用putty或类似的SSH工具登陆VPS或服务器: 登陆后运行:scre ...
- springboot 整合task定时任务
一步:在启动类中加入 加入就会调用定时了. //开启定时任务 开启后就可以被扫描到 @EnableScheduling 二步:建一个tasks工具包 都会被扫描到的了 有三个类 Async ...
- ArcGIS案例学习笔记3_1_ArcMap编辑练习
ArcGIS案例学习笔记3_1_ArcMap编辑练习 计划时间:第三天上午 目的:ArcMap编辑练习 教程: pdf page67 数据: gis_ex10/ex07 方法: 1.新建shp文件 目 ...
- 通过日志恢复SQL Server的历史数据
通过日志恢复SQL Server的历史数据 Posted on 2008-11-14 21:47 代码乱了 阅读(4658) 评论(10) 编辑 收藏 园子里前段时间发过一篇通过日志恢复MSSQL数 ...
- ztree根据treeId展开指定节点并触发单击事件
ztree.expandNode(ztree.getNodeByParam("id",treeId,null));//展开指定节点 ztree.selectNode(ztree.g ...
- 神经网络中的激活函数具体是什么?为什么ReLu要好过于tanh和sigmoid function?(转)
为什么引入激活函数? 如果不用激励函数(其实相当于激励函数是f(x) = x),在这种情况下你每一层输出都是上层输入的线性函数,很容易验证,无论你神经网络有多少层,输出都是输入的线性组合,与没有隐藏层 ...
- CMake Error at cmake/OpenCVModule.cmake:295 (message): No extra modules found in folder:Please provide path to 'opencv_contrib/modules' folder
其实,我们使用的opencv中要用的contrib/modules 是需要额外下载并在cmakelists.txt中指定的 git clone https://github.com/opencv/ ...