C# 使用JQuery取消选中Gridview中的所有复选框

C# 使用JQuery取消选中Gridview中的所有复选框,c#,jquery,asp.net,C#,Jquery,Asp.net,使用JQuery取消选中Gridview中的所有复选框 请参阅更多:C#ASP.NET jQuery “此处不在所有情况下工作”复选框中的“单击页眉”复选框 <script type="text/javascript" language="javascript"> function CheckAll(Checkbox) { var GridView1 = document.getElementById("<%=GridView1.ClientID

使用JQuery取消选中Gridview中的所有复选框

请参阅更多:C#ASP.NET jQuery

“此处不在所有情况下工作”复选框中的“单击页眉”复选框

     <script type="text/javascript" language="javascript">
     function CheckAll(Checkbox) {
     var GridView1 = document.getElementById("<%=GridView1.ClientID %>");
     for (i = 1; i < GridView1.rows.length; i++) {
      GridView1.rows[i].cells[3].getElementsByTagName("INPUT")[0].checked       =Checkbox.checked;
       }} 

函数CheckAll(复选框){
var GridView1=document.getElementById(“”);
对于(i=1;i


HeaderTemplate>
/HeaderTemplate>
是一个
bool
类型属性

您应该为其指定
true
false

GridView1.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked = true;
另外,根据
aspx
代码,您的单元格值应该是
0

(如果您提供了呈现的HTML,则会更容易)

更改此行:

GridView1.rows[i]。单元格[3]。getElementsByTagName(“输入”)[0]。选中=复选框。选中

用这个

GridView1.rows[i]。单元格[0]。getElementsByTagName(“输入”)[0]。选中=复选框。选中

GridView1.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked = true;
$(function() {
    // Get your GridView, to restrict the "check/uncheck all" action only to this GridView (and don't mess up with another controllers in the page)
    var MainGridView = $('#GridView1');  // Set your GridView's Id

    // Bind Your Button to Check All CheckBoxes (Set the Id, or whatever CSS selector to match your CHECK ALL CHECKBOXES button)
    // This CSS selector applied to your needs will be '#chkHeader'. (Use only this piece of code, and do not bind the uncheck to this control too, otherwise it will check and uncheck all everytime)
    $('#ButtonCheckAllCheckBoxes').click(
        function () {
            MainGridView.find("input[type='checkbox']").prop('checked', true);
        }
    );


    // Bind Your Button to Uncheck All CheckBoxes (Set the Id, or whatever CSS selector to match your UNCHECK ALL CHECKBOXES button)
    $('#ButtonUncheckAllCheckBoxes').click(
        function () {
            MainGridView.find("input[type='checkbox']").prop('checked', false);
        }
    );
});