GridView CheckBox 全选

    

    <script type="text/javascript">

        $(function () {

            $("#allCheck").click(function () {  //点击全选按钮

                if ($(this).prop("checked")) {

                    $("#GridView1 :checkbox").prop("checked", true);

                } else {

                    $("#GridView1 :checkbox").prop("checked", false);

                }

            });

 

            $("#GridView1 :checkbox:gt(0)").click(function () {

                var chItem = $("#GridView1 :checkbox:gt(0)");

                var isAllCheck = true;//是否全部选中了

                for (var i = 0; i < chItem.length; i++) {

                    if (!$(chItem[i]).prop("checked")) {

                        isAllCheck = false;

                        break;

                    }

                }

                $("#allCheck").prop("checked", isAllCheck);

            });

        });

    </script>

 

            <asp:GridView ID="GridView1" runat="server" CssClass="dataTable" DataKeyNames="ID">

                <Columns>

                    <asp:TemplateField>

                        <HeaderTemplate>

                            <input type="checkbox" id="allCheck" />

                        </HeaderTemplate>

                        <ItemTemplate>

                            <asp:CheckBox ID="CheckBox1" runat="server" />

                        </ItemTemplate>

                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="操作">

                        <ItemTemplate>

                            <a href="CreateCompanyShop.aspx?cm=<%#Eval("COMPANY") %>" title="详情">

                                <img src="../images/明细.png" width="20" title="详情" height="20" border="0" /></a>

                        </ItemTemplate>

                    </asp:TemplateField>

                </Columns>

            </asp:GridView>

    

 

        // 获取选中的ID集合

        private List<string> GetCheckRowIds()

        {

            //获取复选框被选中的行id

            List<string> lst = new List<string>();

            foreach (GridViewRow row in GridView1.Rows)

            {

                CheckBox cb = row.Cells[0].FindControl("CheckBox1") as CheckBox;

                if (cb.Checked)

                {

                    lst.Add(GridView1.DataKeys[row.RowIndex].Value.ToString());

                    //ids += "'" + GridView1.DataKeys[row.RowIndex].Value + "',";

                }

            }

            return lst;

        }

    

    

        public bool DeleteCMShopByIdList(List<string> idList)

        {

            string ids = string.Empty;

            foreach (string item in idList)

            {

                ids += "'" + item + "',";

            }

            ids = ids.Trim(',');

            string sql = "DELETE Company_Shop WHERE ID  IN(" + ids + ");";

            SqlTransaction tran = dbhelper.GetTransAction();

            try

            {

                dbhelper.ExcuteNonequery(sql, tran);

                tran.Commit();

                return true;

            }

            catch (Exception)

            {

                tran.Rollback();

            }

            finally

            {

                tran.Dispose();

            }

            return false;

        }

        

 

 

 

   //TWO

    private string GetCheckRowIds()

    {

        //获取复选框被选中的行id

        string ids = string.Empty;

        foreach (GridViewRow row in GridView1.Rows)

        {

            CheckBox cb = row.Cells[0].FindControl("CheckBox1") as CheckBox;

            if (cb.Checked)

            {

                ids += "" + GridView1.DataKeys[row.RowIndex].Value + ",";

            }

        }

        if (ids != string.Empty)

        {

            ids = ids.TrimEnd(',');

        }

        return ids;

    }        

        

        

    protected void btnSure_Click(object sender, EventArgs e)

    {

        string ids = GetCheckRowIds();

        if (ids == string.Empty)

        {

            Page.ClientScript.RegisterStartupScript(this.GetType(), "提示", "<script>alert('你没有选择任何选项')</script>");

            return;

        }

        int undoCount = 0;

        string[] idArray = ids.Split(',');

        IDbTransaction tran = ConnectStringConfig.GetTran();

        try

        {

            foreach (string id in idArray)

            {

                string strStatus = "";

                string sql = "select ID,TYPE,STATUS from tasks_direct where id = " + id + "";

                DataTable dttask = dbHelper.GetDataTable(sql);

                foreach (DataRow dr in dttask.Rows)

                {

                    strStatus = dr["STATUS"].ToString();

                    if (strStatus == "00")

                    {

                        boTaskDirect.ConfirmMove(dr["ID"].ToString(), boTaskDirect.TblTaskDirect.WEIGHT.Value, true, tran);

                        undoCount++;

                    }

                }

            }

            tran.Commit();

        }

        catch (Exception ex)

        {

            tran.Rollback();

            Response.Redirect(SysConfig.ErrorPage + ex.Message);

        }

        finally

        {

            tran.Dispose();

        }

        string message = undoCount.ToString() + " 个任务确认成功!";

        Page.ClientScript.RegisterStartupScript(this.GetType(), "提示", "<script>alert('" + message + "')</script>");

        Paginationer.BindData();

    }

GridView CheckBox 全选的更多相关文章

  1. TreeView checkbox 全选

    在使用TreeView 控件 ,进行权限管理的时候,需要使用 checkbox全选. 勾选父节点,子节点全部选中.取消父节点,子节点不选中. 勾选子节点,父节点也选中. 以下是在使用的例子: < ...

  2. JS checkbox 全选 全不选

    /* JS checkbox 全选 全不选 Html中checkbox: <input type="checkbox" name="cbx" value= ...

  3. checkbox全选,反选,取消选择 jquery

    checkbox全选,反选,取消选择 jquery. //checkbox全部选择 $(":checkbox[name='osfipin']").each(function(){ ...

  4. js初学—实现checkbox全选功能

    布局如下: <p ><input type="checkbox" id="che1"/>全选</p><div id=& ...

  5. checkbox全选与反选

    用原生js跟jquery实现checkbox全选反选的一个例子 原生js: <!DOCTYPE html> <html lang="en"> <hea ...

  6. angularjs实现 checkbox全选、反选的思考

    之前做了一周的打酱油测试,其实感觉其实测试也是上辈子折翼的天使. 好长时间没写代码,感觉好多都不会了. 感谢这周没有单休,我能看熬夜看奥运了.我能有时间出去看个电影,我能有时间出去逛个商城,我能有时间 ...

  7. 利用jQuery实现CheckBox全选/全不选/反选

    转自:http://www.cnblogs.com/linjiqin/p/3148259.html jQuery有些版本中实现CheckBox全选/全不选/反选会有bug,经测试jquery-1.3. ...

  8. jquery数组之存放checkbox全选值示例代码

    使用jquery数组可以存放checkbox全选值,下面有个不错的示例,感兴趣的朋友可以参考下. 复制代码代码如下: <input type="checkbox" id=&q ...

  9. jQuery实现CheckBox全选、全不选

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

随机推荐

  1. Spring @Service生成bean名称的规则

    今天碰到一个问题,写了一个@Service的bean,类名大致为:BKYInfoServcie.java dubbo export服务的配置: <dubbo:service interface= ...

  2. C/C++ 右值引用 及 函数调用栈剖析

    参考: [1]. C/C++堆栈指引: http://www.cnblogs.com/Binhua-Liu/archive/2010/08/24/1803095.html [2]. C++临时变量的生 ...

  3. 项目支持Servlet3.0的新特性

    一.Servlet3.0介绍 Servlet3.0是Java EE6规范的一部分,Servlet3.0提供了注解(annotation),使得不再需要在web.xml文件中进行Servlet的部署描述 ...

  4. ecshop的特点,持续加新

    一.目录文件结构 入口文件index.php,define('IN_ECS', true); 只有为true时才可以进入. 首先加入init.php,在这个文件里: @ini_set('memory_ ...

  5. MS sql server 基础知识回顾(二)-表连接和子查询

    五.表连接 当数据表中存在许多重复的冗余信息时,就要考虑将这些信息建在另一张新表中,在新表中为原表设置好外键,在进行数据查询的时候,就要使用到连接了,表连接就好像两根线,线的两端分别连接两张表的不同字 ...

  6. 说一说inline-block的奇葩之处

    今天本来想聊一下margin和padding,但是当我给div加了一个display:inline-block之后,发现一个问题: .box_demo{border: 1px solid #333;w ...

  7. js onkeypress与onkeydown 事件区别详细说明

    keypress只适用于有字符输入的按键 而keyup/keydown包含了Ctrl, Shift之类的情况 Firefox在处理onKeyDown/onKeyPress事件时存在漏洞,恶意网页可能利 ...

  8. Sql 邮件发送

    select name from msdb.dbo.sysmail_profile --邮件发送日志 SELECT * FROM msdb.dbo.sysmail_event_log delete F ...

  9. Get the Uniqueid of Action Originate in the AMI

    [asterisk-users] Get the Uniqueid of Action Originate in the AMI Adolphe Cher-Aime acheraime at gmai ...

  10. linux磁盘与文件系统的管理

    本文涉及命令:dumpe2fs.df.du.fdisk.mkfs.mke2fs.fsck.badblocks.mount.umount.e2label.tune2fs.hdparm.parted 概念 ...