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. 使用Idhttp.get('') 造成假死(堵塞),请问线程idhttp怎么才能做到不出错?

    参考这个帖子 http://blog.csdn.net/chyoma/article/details/50839715

  2. 相机标定:关于用Levenberg-Marquardt算法在相机标定中应用

    LM算法在相机标定的应用共有三处. (1)单目标定或双目标定中,在内参固定的情况下,计算最佳外参.OpenCV中对应的函数为findExtrinsicCameraParams2. (2)单目标定中,在 ...

  3. 在后台 .cs 中执行前台的js 函数

    <script type="text/javascript" language="javascript"> <!-- function ope ...

  4. linux 搭建 nexus 私服及配置

    安装篇 1.tar -zxvf nexus-latest-bundle.tar.gz 2.cd nexus-2.13.0-01/bin 3../nexus start 这时可能提示 ********* ...

  5. git 放弃本地修改 强制更新

    git reset --hard origin/master

  6. frame中隐藏横向滚动条

    设置frame的scrolling="yes",在右侧页面的body里加入: style="overflow-x:hidden;"  如:<body st ...

  7. iOS 解析json串

    NSString *json = @"[{\"name\":\"a1\",\"items\":[{\"x1\" ...

  8. 计算机网络 学习笔记-传输层:TCP协议简介

    概述: TCP传输前先要建立连接 TCP在传输层 点对点,一条TCP只能连接两个端点 可靠传输.无差错.不丢失.不重复.按顺序 全双工 字节流 TCP报文段 TCP报文段的报头前20字节是固定的,后面 ...

  9. delegate事件绑定

    为了代码的健壮性,绑定事件之前先解绑再进行绑定. var _$div = $("#id");_$div.undelegate("click mouseover mouse ...

  10. pci

    https://www.ibm.com/developerworks/cn/linux/l-pci/