动态生成的Gridview的前台html代码如下:

    <table class="usertableborder" cellspacing="0" rules="all" border="1" id="gvEquData"
        style="border-collapse: collapse;">
        <thead>
            <tr class="Freezing">
                <th scope="col" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    序号
                </th>
                <th scope="col" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    设备连接状态
                </th>
                <th scope="col" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <a href="javascript:__doPostBack('gvEquData','Sort$samid')">POS机编号</a>
                </th>
                <th scope="col" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <span class="farupdateflag">
                        <input id="gvEquData_ctl01_farupdateflag" type="checkbox" name="gvEquData$ctl01$farupdateflag" /></span>FAR参数更新标识
                </th>
                <th scope="col" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <span class="rwsoftupdateflag">
                        <input id="gvEquData_ctl01_rwsoftupdateflag" type="checkbox" name="gvEquData$ctl01$rwsoftupdateflag" /></span>软件更新标识
                </th>
                <th scope="col" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <span class="mtksoftupdateflag">
                        <input id="gvEquData_ctl01_mtksoftupdateflag" type="checkbox" name="gvEquData$ctl01$mtksoftupdateflag" /></span>MTK软件更新标识
                </th>
                <th scope="col" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <a href="javascript:__doPostBack('gvEquData','Sort$mtkcsnver')">MTK中黑名单版本</a>
                </th>
                <th scope="col" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <span class="rfsimsoftupdateflag">
                        <input id="gvEquData_ctl01_rfsimsoftupdateflag" type="checkbox" name="gvEquData$ctl01$rfsimsoftupdateflag" /></span>RFSIM软件更新标识
                </th>
                <th scope="col" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <span class="iniupdateflag">
                        <input id="gvEquData_ctl01_iniupdateflag" type="checkbox" name="gvEquData$ctl01$iniupdateflag" /></span>INI文件更新标识
                </th>
                <th scope="col" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <span class="posupdateflag">
                        <input id="gvEquData_ctl01_posupdateflag" type="checkbox" name="gvEquData$ctl01$posupdateflag" /></span>POS参数更新标识
                </th>
                <th scope="col" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <a href="javascript:__doPostBack('gvEquData','Sort$bcbeginno')">补采起始号</a>
                </th>
                <th scope="col" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <a href="javascript:__doPostBack('gvEquData','Sort$bcendno')">补采截至号</a>
                </th>
                <th scope="col" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <a href="javascript:__doPostBack('gvEquData','Sort$bcbegindate')">补采起始日期</a>
                </th>
                <th scope="col" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <a href="javascript:__doPostBack('gvEquData','Sort$bcenddate')">补采结束日期</a>
                </th>
                <th scope="col" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <a href="javascript:__doPostBack('gvEquData','Sort$bctotalcount')">补采总条数</a>
                </th>
                <th scope="col" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <a href="javascript:__doPostBack('gvEquData','Sort$bccurrentcount')">
                        补采已上传条数</a>
                </th>
                <th scope="col" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <a href="javascript:__doPostBack('gvEquData','Sort$busno')">车辆编号</a>
                </th>
                <th scope="col" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <a href="javascript:__doPostBack('gvEquData','Sort$driverno')">司机编号</a>
                </th>
                <th scope="col" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <a href="javascript:__doPostBack('gvEquData','Sort$mtkusrver')">MTK中USR参数版本</a>
                </th>
                <th scope="col" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <a href="javascript:__doPostBack('gvEquData','Sort$mtkfarver')">MTK中FAR参数版本</a>
                </th>
                <th scope="col" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <a href="javascript:__doPostBack('gvEquData','Sort$mtkparver')">MTK中PAR参数版本</a>
                </th>
            </tr>
        </thead>
        <tbody>
            <tr onmouseover="Color=this.style.backgroundColor;this.style.backgroundColor='RosyBrown'"
                onmouseout="this.style.backgroundColor=Color;" ondblclick="showDetailInfo('?id=');return false;"
                style="background-color: Silver;">
                <td style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    1
                </td>
                <td style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    否
                </td>
                <td align="center" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    &nbsp;
                </td>
                <td style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <span class="farupdateflag">
                        <input id="gvEquData_ctl02_cbx_-farupdateflag" type="checkbox" name="gvEquData$ctl02$cbx_-farupdateflag"
                            checked="checked" /></span>
                </td>
                <td style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <span class="rwsoftupdateflag">
                        <input id="gvEquData_ctl02_cbx_-rwsoftupdateflag" type="checkbox" name="gvEquData$ctl02$cbx_-rwsoftupdateflag"
                            checked="checked" /></span>
                </td>
                <td style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <span class="mtksoftupdateflag">
                        <input id="gvEquData_ctl02_cbx_-mtksoftupdateflag" type="checkbox" name="gvEquData$ctl02$cbx_-mtksoftupdateflag"
                            checked="checked" /></span>
                </td>
                <td align="center" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    &nbsp;
                </td>
                <td style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <span class="rfsimsoftupdateflag">
                        <input id="gvEquData_ctl02_cbx_-rfsimsoftupdateflag" type="checkbox" name="gvEquData$ctl02$cbx_-rfsimsoftupdateflag"
                            checked="checked" /></span>
                </td>
                <td style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <span class="iniupdateflag">
                        <input id="gvEquData_ctl02_cbx_-iniupdateflag" type="checkbox" name="gvEquData$ctl02$cbx_-iniupdateflag"
                            checked="checked" /></span>
                </td>
                <td style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    <span class="posupdateflag">
                        <input id="gvEquData_ctl02_cbx_-posupdateflag" type="checkbox" name="gvEquData$ctl02$cbx_-posupdateflag" /></span>
                </td>
                <td align="center" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    &nbsp;
                </td>
                <td align="center" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    &nbsp;
                </td>
                <td align="center" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    &nbsp;
                </td>
                <td align="center" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    &nbsp;
                </td>
                <td align="center" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    &nbsp;
                </td>
                <td align="center" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    &nbsp;
                </td>
                <td align="center" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    6
                </td>
                <td align="center" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    &nbsp;
                </td>
                <td align="center" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    &nbsp;
                </td>
                <td align="center" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    &nbsp;
                </td>
                <td align="center" style="white-space: nowrap; word-break: keep-all; word-wrap: keep-all">
                    &nbsp;
                </td>
            </tr>
        </tbody>
        <tfoot>
        </tfoot>
    </table>

js代码如下:

   <script type="text/javascript">
var isReturnStatus = function (data) {
if (data.length >= 5) {
strs = data.split(","); //字符分割
if (strs.length >= 3) {
if (strs[0] == "empty") {
alert('主键为空,无法更新!'); //重置选中状态
if (strs[1] == "1") {
document.getElementById(strs[2]).checked = false;
}
else {
document.getElementById(strs[2]).checked = true;
}
}
}
}
initCheckedStaus();
}
$(function () {
//初始化全选按钮选中状态
$("thead input[type='checkbox']").each(function () {
var id = $(this).attr("id");
var name = id.substr(16);
var v1 = "tbody ." + name;
var v = v1 + " input[type='checkbox']";
var h = "thead ." + name;
if ($(v).length == $(v1 + " input:checked").length) {
$("#gvEquData_ctl01_" + name).attr("checked", true);
}
else {
$("#gvEquData_ctl01_" + name).attr("checked", false);
}
}); //监听表中复选框单击事件
$("tbody").find("input:checkbox").each(function (key, val) {
$(val).click(function () {
var cbxId = $(this).attr("id");
var state = $(this).attr("checked");
$.post("Ajax/UpdateStatus.ashx", { "id": cbxId, "isChecked": state, "fid": "SamID" }, isReturnStatus);
});
});
//监听标题中复选框单机事件
$("thead").find("input:checkbox").click(
function () {
if (confirm("确定要更新这一列数据吗?") == true) {
var cbxId = $(this).attr("id"); var name = cbxId.substr(16);
var v = "tbody ." + name + " input[type='checkbox']"; if ($(this).attr("checked") == "checked") {
$(v).attr("checked", true);
}
else {
$(v).attr("checked", false);
} var state = $(this).attr("checked");
$.post("Ajax/UpdateStatus.ashx", { "id": cbxId, "isChecked": state }, isReturnStatus);
}
else {
if ($(this).attr("checked") == "checked") {
$(this).attr("checked", false);
}
else {
$(this).attr("checked", true);
}
}
});
}); //清除查询条件
function chearData() {
var lineNo = document.getElementById('<%=txtLineNO.ClientID %>');
var deviceNo = document.getElementById('<%=txtDeviceNO.ClientID %>');
var busNo = document.getElementById('<%=txtBusNO.ClientID %>');
lineNo.value = "";
deviceNo.value = "";
busNo.value = "";
}
//即时监听复选框状态
function initCheckedStaus() {
$(function () {
//即时监听表头复选框状态
$("thead input[type='checkbox']").each(function () {
var id = $(this).attr("id");
var name = id.substr(16);
var v1 = "tbody ." + name;
var v = v1 + " input[type='checkbox']";
var h = "thead ." + name;
if ($(v).length == $(v1 + " input:checked").length) {
$("#gvEquData_ctl01_" + name).attr("checked", true);
}
else {
$("#gvEquData_ctl01_" + name).attr("checked", false);
}
});
});
}
//显示详情页面
function showDetailInfo(url) {
showWin(800, 560, "EquStatusDetail.aspx" + url, "detail");
}
//显示设置页面
function showSet(url) {
showWin(800, 600, "ShowSet.aspx" + url,"set");
}
//触发查询事件
function searchData() {
var btn = document.getElementById("<%=btnQuery.ClientID %>");
btn.click();
}
//处理ajax和ScriptManager的冲突
function load() {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
}
function EndRequestHandler() {
$(function () {
$("tbody").find("input:checkbox").each(function (key, val) {
$(val).click(function () {
var cbxId = $(this).attr("id");
var state = $(this).attr("checked");
$.post("Ajax/UpdateStatus.ashx", { "id": cbxId, "isChecked": state, "fid": "SamID" }, isReturnStatus);
});
});
$("thead").find("input:checkbox").click(
function () {
if (confirm("确定要更新这一列数据吗?") == true) {
var cbxId = $(this).attr("id"); var name = cbxId.substr(16);
var v = "tbody ." + name + " input[type='checkbox']";
if ($(this).attr("checked") == "checked") {
$(v).attr("checked", true);
}
else {
$(v).attr("checked", false);
} var state = $(this).attr("checked");
$.post("Ajax/UpdateStatus.ashx", { "id": cbxId, "isChecked": state }, isReturnStatus);
}
else {
if ($(this).attr("checked") == "checked") {
$(this).attr("checked", false);
}
else {
$(this).attr("checked", true);
}
}
});
});
initCheckedStaus();
}
</script>

ajax代码如下:

  public class UpdateStatus : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
int isChecked = context.Request["isChecked"] == "checked" ? 1 : 0;
string colId=context.Request["id"]; string name = colId.Substring(colId.LastIndexOf('_')+1, colId.Length - colId.LastIndexOf('_')-1);
int result=0; if (QuarrysClass.CheckFlag.ToLower().IndexOf("@" + name + "@") != -1)
{
string selectStr = QuarrysClass.StrWhere;
//控制前台刷新
result = EquSearchBll.equBll.UpdateAllChecked(name, isChecked, selectStr) == 1 ? 2 : EquSearchBll.equBll.UpdateAllChecked(name, isChecked, selectStr);
}
else
{
if (name.Contains('-'))
{
string idName = context.Request["fid"];
string[] arrays = name.Split('-');
string id = arrays[0];
if (string.IsNullOrEmpty(id)) //主键为空无法更新
{
context.Response.Write("empty," + isChecked+"," + colId);
return;
} string fieldName = arrays[1];
string strWhere = string.Format(" and {0}='{1}'",idName,id);
result = EquSearchBll.equBll.UpdateAllChecked(fieldName, isChecked, strWhere);
}
} context.Response.Write(result);
} public bool IsReusable
{
get
{
return false;
}
}
}

jquery控制动态生成的gridview中多列checkbox的全选反选及自动判断是否全选状态的更多相关文章

  1. JQuery实现动态生成树形菜单

    jQuery实现动态生成树形菜单 有一个需求:菜单导航条需要依据不同的权限动态提取出来.计划是将功能模块与用户权限之间的关系保持到一个配置表中.所以功能菜单的话就需要动态提取出来再显示.借助jquer ...

  2. jQuery对于动态生成的元素绑定无效的问题~~

    问题:很多时候发现,对动态生成的元素绑定click事件是无效的- 原因:直接绑定到动态生成的元素是无效的,是因为Jquery扫描文档找出所有的$(‘’)元素,并把函数绑定到每个元素的click事件上, ...

  3. jquery给动态生成的元素绑定事件,on函数

    首先先解释一下什么是动态生成的元素:动态生成的元素即我们用jquery的内部插入函数append()所生成的html代码.相对的也有静态生成的元素:即直接编写在页面的html代码. 下面通过例子来讲解 ...

  4. jQuery为动态生成的select元素添加事件的方法

    项目中需要在点击按钮时动态生成select元素,为防止每次点击按钮时从服务器端获取数据(因为数据都是相同的),可以这样写代码 1.首先定义全局js变量 var strVoucherGroupSelec ...

  5. Jquery mobile动态生成ListView调用刷新方法报错

    错误:cannot call methods on listview prior to initialization... 示例: <div data-role="page" ...

  6. jquery validate 动态生成的多个同名input的验证

    我的应用场景是,添加和修改入库单的明细,明细是以表格的形式呈现,可以动态添加商品,用jquery.validate插件做数据验证. 由于jquery.validate插件验证同名的input时只验证第 ...

  7. jQuery获取动态生成的元素

    需求描述:页面上可以动态添加数据,比如table,点击按钮可以动态添加行.又或页面 加载时table数据是通过ajax从后台获取的.而这时我们想要获取其中的某个值,又该如何获取呢? 如果是要通过某个事 ...

  8. JQuery对于动态生成的标签绑定事件失效

    JQuery对整个html文档进行dom操作后,我们要想动态绑定事件,有两种方法 1.在进行dom操作时,在标签中写上onclick="afun()" 2.利用document的操 ...

  9. Jquery给动态生成的对象绑定事件

    $(document).on("blur", ".Text1", function () { var index = this.id.replace('txtS ...

随机推荐

  1. Python 模块续和面向对象的介绍(六)

    一.基本模块 shutil 文件.目录.压缩包的处理模块 shutil.copyfile(src, dst) 拷贝文件 >>> shutil.copyfile('a.log','b. ...

  2. JavaScript学习笔记(四十四) 装饰器

    装饰器模式(Decorator) 在装饰器模式中,可以在运行时给一个对象动态的添加额外的功能.当和静态类打交道的时候(static classes),这可能是一个挑战.但在JavaScript中,对象 ...

  3. 腾讯QQ:异地登陆也被封号,你们是怎么决策的???

    此文我想放到首页,让很多其它的人看到,更期待有人能解释一下.希望管理员给开绿灯. 今天真是费解,我的手机号是青岛的.可是我在武汉工作,因为是3G的卡,全国没有漫游,打电话也没多少钱,所以就没换号. 谁 ...

  4. jsp生命周期和工作原理

    jsp的工作原理jsp是一种Servlet,但是与HttpServlet的工作方式不太一样.httpservlet是先由源代码编译为class文件后部署到服务器下的,先编译后部署.而jsp则是先部署后 ...

  5. DP HDIJ1421 搬宿舍

    Problem Description 搬寝室是很累的,xhd深有体会.时间追述2006年7月9号,那天xhd迫于无奈要从27号楼搬到3号楼,因为10号要封楼了.看着寝室里的n件物品,xhd开始发呆, ...

  6. 01-IOSCore - NSString、NSFileManager、NSBundle、StringAndObjectConvert

    模型 1 将数据存储到硬盘,将硬盘上的数据在读回内存 2 文件存储: NSFileHandle 对文件的读写 NSData 二进制数据 NSString 表示文件路径 NSFileManager(对文 ...

  7. Python 数据分析(二 本实验将学习利用 Python 数据聚合与分组运算,时间序列,金融与经济数据应用等相关知识

    Python 数据分析(二) 本实验将学习利用 Python 数据聚合与分组运算,时间序列,金融与经济数据应用等相关知识 第1节 groupby 技术 第2节 数据聚合 第3节 分组级运算和转换 第4 ...

  8. VS2008查看dll导出函数

    打开Visual Studio 2008 命令提示,使用命令 [plain] view plaincopyprint? dumpbin /exports simple.dll 即可查看

  9. 华为OJ:计算两个自然时间相加

    按要求一步步做就好 import java.util.Scanner; public class dateAdd { public static void main(String args[]){ S ...

  10. Java基础05 实施接口

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 在封装与接口中,private关键字封装了对象的内部成员.经过封装,产品隐藏了内部 ...