protected void Button3_Click(object sender, EventArgs e)
    {
        string strSQL = "";
        for (int i = 0; i < this.GridView1.Rows.Count; i++)
        {
            string str = this.GridView1.Rows[i].Cells[1].Text.Trim();
            if ((this.GridView1.Rows[i].FindControl("CheckBox1") as CheckBox).Checked == true)
            {
                strSQL += "select * from SYS_BPS_USERS where USER_Account ='" + str + "';";
            }
        }
这是后台获得checkbox选中的代码,我还想添加都没选则alert(“错误”)的方法

解决方案 »

  1.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="JquerySelectItem.aspx.cs" Inherits="JquerySelectItem" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <style type="text/css">
            * { margin:0px; padding:0px;} 
             body{ font-size:12px;}
             #header{ cursor:pointer;}
            #header{line-height:25px; background:#ccc; cursor:pointer; border:1px solid #000;}
            #content{ background:#ccc; border:1px solid #000;}
            #content p{ line-height:25px;}
        </style>
        <script src="jquery/jquery-1.6.2.min.js" type="text/javascript"></script>
        <script type="text/javascript" language="javascript">
            $(function () {
                //全选checkbox
                $(":button[value=全选]").bind("click", function () {
                    $(":checkbox").attr("checked", true)//attr()更改属性方法
                });
                //全不选checkbox
                $(":button[value=全不选]").bind("click", function () {
                    $(":checkbox").attr("checked", false)//attr()更改属性方法
                });
                //反选,先把兄弟选上,
                $(":button[value=返选]").click(function () {
                    $(":checked").siblings().attr("checked", true).end().attr("checked", false); //反选,先把兄弟选上,
                });
            });
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
          <div style="width:663px; margin-top:100px;height:222px;">
            <p>
                <input checked="checked" type="checkbox" />选择框1
                <input checked="checked" type="checkbox" />选择框2
                <input checked="checked" type="checkbox" />选择框3
                <input type="checkbox" />选择框4
                <input type="checkbox" />选择框5
                <input type="checkbox" />选择框6
                <input type="checkbox" />选择框7
                <input type="checkbox" />选择框8
            </p>
            <p style=" margin-top:23px;">
                <input style=" width:100px; height:25px;" type="button" value="全选" />
                <input style=" width:100px; height:25px;" type="button" value="全不选" />
                <input style=" width:100px; height:25px;" type="button" value="返选" />
            </p>
           </div>  
        </div>
        </form>
    </body>
    </html>jquery
    类似这种,放在gridview其实一样
      

  2.   

    GridViewRow drv = ((GridViewRow)(((System.Web.UI.WebControls.ImageButton)(sender)).Parent.Parent));
    System.Web.UI.WebControls.CheckBox cbox = (System.Web.UI.WebControls.CheckBox)GridView1.Rows[drv.RowIndex].FindControl("chbCheck");主要是第二句,你参考下,根据你的情况修改下就可以了
      

  3.   

    我已经找到解决办法了
     protected void Button3_Click(object sender, EventArgs e)
        {
            bool bl = false;
            for (int i = 0; i < this.GridView1.Rows.Count; i++)
            {
                string str = this.GridView1.Rows[i].Cells[1].Text.Trim();
                if ((this.GridView1.Rows[i].Cells[0].FindControl("CheckBox1") as CheckBox).Checked == true)
                {
                    bl = true;
                    break;            }
            }
            if (!bl)
            {            Response.Write("<script language='javascript'>alert('错误');</script>");
                return;
            }
            string strSQL = "";
            for (int i=0;i < this.GridView1.Rows.Count; i++)
            {
                string str = this.GridView1.Rows[i].Cells[1].Text.Trim();
                if ((this.GridView1.Rows[i].FindControl("CheckBox1") as CheckBox).Checked == true)
                {
                    strSQL += "select * from SYS_BPS_USERS where USER_Account ='" + str + "';";
                }
            }谢谢啦!
      

  4.   

    为什么我试了一下二楼的方法,没有反应呢。。LZ想要的是在后台解决的吧在前台用JQ的办法会不会受到网页兼容性的问题呢