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();

    }

最新文章

  1. MyBatis3学习--来源自用户指南
  2. [.net 面向对象编程基础] (10) 类的成员(字段、属性、方法)
  3. http的500,502,504错误
  4. jQuery知识点总结(第三天)
  5. [Python] Python 之 __new__() 方法与实例化
  6. Python是编译运行的
  7. Data Mining Resources
  8. string evaluated instead to freemarker.template.SimpleScalar
  9. iOS圆盘转动引导图的简单实现
  10. 使用Spring的JAVA Mail支持简化邮件发送(转)
  11. Learning part-based templates from large collections of 3D shapse CorrsTmplt Kim 代码调试
  12. linux命令(方可)
  13. html5 input输入实时检测以及延时优化
  14. Python XML解析之DOM
  15. Python 入门基础15 --shutil、shelve、log常用模块2、项目结构
  16. gin的url查询参数解析
  17. Codeforces 835F Roads in the Kingdom - 动态规划
  18. log4j(五)——如何控制不同目的地的日志输出?
  19. [转]How do you build a database?
  20. 美团外卖商家获取订单-signToken取值

热门文章

  1. oracle start with connect by prior 递归查询
  2. 【摘】top命令
  3. Karma 4 - Karma 集成 Webpack 进行单元测试
  4. git学习系列--六分之一
  5. VM 虚拟机 Error 1324. The path My Documents contains a invalid chara 。
  6. PHP&amp;MySQL 语法
  7. 【EF学习笔记10】----------主从表级联操作
  8. 多个 git ssh key 配置 Ubuntu os
  9. AIX系统程序异常不释放光驱处理
  10. uniq,sort,