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 ...
随机推荐
- 发现一个好办法-有问题可以到UNITY论坛搜索
特别专业的问题,较新技术,可以到UNITY论坛搜索或发问,那里,或许会有UNITY的官方技术支持回答 https://forum.unity.com/threads/remote-deep-profi ...
- elk日志平台搭建小记
最近抽出点时间,搭建了新版本的elk日志平台 elastaicsearch 和logstash,kibana和filebeat都是5.6版本的 中间使用redis做缓存,版本为3.2 使用的系统为ce ...
- linux下mysql开启远程访问权限 防火墙开放3306端口
linux下mysql开启远程访问权限 防火墙开放3306端口 转载 2017-01-21 作者:JAVA-ANDROID 这篇文章主要为大家详细介绍了linux下mysql开启远程访问权限,防 ...
- 【转】JS windows.open()详解
window.open(url, name, features, replace) Arguments - 参数 url 可选字符串参数,指向要在新窗口中显示的文档的URL.如果省略该参数,或者参 ...
- ImportError: No module named etree.ElementTree问题解决方法
学习python操作xml文档过程中碰到的ImportError: No module named etree.ElementTree问题,问题现象比较奇怪,做个记录. 操作环境 Python3.6+ ...
- 火狐的3d视图插件Tilt 3D
15年的时候,使用过此功能.后来没注意就发现没了.firefox在47之后就停止自带了. 换成插件了. https://addons.mozilla.org/en-US/firefox/addon/t ...
- 3.AOP入门1.md
目录 1.定义 1.1基本概念 2. 1.定义 1.1基本概念 AOP:aspect object programing面向切面编程 aop编程的要点在于关注点和切入点 关注点:指的是代码中的重复部分 ...
- ArcGIS Python编程案例-电子资料链接
ArcGIS Python编程案例(1)-Python语言基础 https://www.jianshu.com/p/dd90816d019b ArcGIS Python编程案例(2)-使用ArcPy编 ...
- C:\\MFC控件大小随窗体大小而改变
一.大小和位置都改变 1.首先为窗体类添加CRect m_rect,该成员变量用来记录窗体的当前大小. 2.在类向导里面(Ctrl+W),为窗体添加消息WM_SIZE的响应函数OnSize(): 注意 ...
- 有关于tomcat启动时,利用listener来执行某个方法
今天,项目经理让我调查一下(目的是锻炼我),刚开始的时候说用listener来实现服务器启动然后某个项目跟着启动.其实就是tomcat启动的时候去执行某个方法,通过这个方法启动某个项目.我网上调查了一 ...