如何判断只选择了GridView中的一个CheckBox?

解决方案 »

  1.   

    GridView中每个CheckBox都赋对应的值,循环判断
      

  2.   

    选中任意1项,点击事件然后循环得到选中的值for (int i = 0; i < rpMyReceiveComment.Items.Count; i++)
                {
                    CheckBox CB = (CheckBox)rpMyReceiveComment.Items[i].FindControl("single_Chk");
                    if (CB.Checked == true)
                    {
                        string delID = ((HiddenField)rpMyReceiveComment.Items[i].FindControl("commentid")).Value;//选中的四项值
                    }
                }
         <asp:CheckBox ID="single_Chk" name="selectAll" runat="server" />  <asp:HiddenField ID="commentid" Value='<%#Eval("commentid")%>' runat="server"/> 
      

  3.   

    int selected = 0;
    foreach(GridViewRow row in GridView1.Rows) {
          if(((CheckBox)row.FindControl("CheckBox1")).Checked) selected++;
    }
    Console.Write(selected);
      

  4.   

    for (int i = 0; i < rpMyReceiveComment.Items.Count; i++) 
                { 
                    CheckBox CB = (CheckBox)rpMyReceiveComment.Items[i].FindControl("single_Chk"); 
                    if (CB.Checked == true) 
                    { 
                        string delID = ((HiddenField)rpMyReceiveComment.Items[i].FindControl("commentid")).Value;//选中的四项值 
                    } 
                } 
        <asp:CheckBox ID="single_Chk" name="selectAll" runat="server" />  <asp:HiddenField ID="commentid" Value=' <%#Eval("commentid")%>' runat="server"/> 
    这两个都不错
      

  5.   

     js里也可以做,
                       var temp = 0;
                    function submit(){


    var allBox=document.getElementsByName("checkbox");
        for(var i=0;i<allBox.length;i++){
        if(allBox[i].checked==true){
        temp++;
         
        }
      
        }
      
      
        if(temp==0){
         ..........  
                      }
        
        else{
                         ............
                       }
                     }