none
How to Check all the Checkboxes in DataGridView? RRS feed

  • Question

  • Hi to All!

    I need To Select All the Checkboxes to be Selected in the Gridview, with Single Event

    Thanks in Advance

    Tuesday, July 27, 2010 12:26 PM

Answers

  • Hi to All!

    I need To Select All the Checkboxes to be Selected in the Gridview, with Single Event

    Thanks in Advance


    Hello Navaneethapperumal,

        Kindly, find the code below to achieve the same:

     foreach (DataGridViewRow dgv in dgtest.Rows)
          {
            dgv.Cells["chk"].Value = true;
          }

    dgtest --- is the DataGrid Control and have a DataGridCheckBoxColumn naming "chk" in DataGrid from the Designer.

    Add the above code in the CheckBox naming "Select All" above the DataGrid or according to your requirement..

    Kindly, let me know if you need further help!

     

    Thanks,

    Paras Sanghani

    Mark As Answer if it helped you.

     

    Tuesday, July 27, 2010 12:36 PM
  • Hope this will help you 

    protected void chkSelectAll_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox chk;
            foreach (GridViewRow rowItem in GridView1.Rows)
            {
                chk = (CheckBox)(rowItem.Cells[5].FindControl("chk1"));
                chk.Checked = ((CheckBox)sender).Checked;
            }
        }

    Tuesday, July 27, 2010 1:06 PM

All replies

  • Hi to All!

    I need To Select All the Checkboxes to be Selected in the Gridview, with Single Event

    Thanks in Advance


    Hello Navaneethapperumal,

        Kindly, find the code below to achieve the same:

     foreach (DataGridViewRow dgv in dgtest.Rows)
          {
            dgv.Cells["chk"].Value = true;
          }

    dgtest --- is the DataGrid Control and have a DataGridCheckBoxColumn naming "chk" in DataGrid from the Designer.

    Add the above code in the CheckBox naming "Select All" above the DataGrid or according to your requirement..

    Kindly, let me know if you need further help!

     

    Thanks,

    Paras Sanghani

    Mark As Answer if it helped you.

     

    Tuesday, July 27, 2010 12:36 PM
  • 1:Create one column called "Select All"

    <asp:TemplateField>
          <HeaderTemplate>
            <asp:CheckBox ID="cbSelectAll" runat="server" Text="Select All" OnClick="selectAll(this)" Width="90px" />
          </HeaderTemplate>
          <HeaderStyle HorizontalAlign="Left" />
          <ItemStyle HorizontalAlign="Left" />
            <EditItemTemplate>          
            </EditItemTemplate>
            <ItemTemplate>
              <asp:CheckBox ID="chkObjective" runat="server" OnClick="select(this)" />
            </ItemTemplate>
     </asp:TemplateField>
    

    2: Call the javascript function to select/Deselect all check boxes

     function selectAll(invoker) {
            var inputElements = document.getElementsByTagName('input');
            var btnEnabled = document.getElementById("<%=ftrButton.ClientID%>");
            for (var i = 0; i < inputElements.length; i++) {
              var myElement = inputElements[i];
              if (myElement.type === "checkbox") {
                myElement.checked = invoker.checked;            
              }
              else {
                myElement.checked = invoker.UnChecked
                
              }          
            }
          }
    


    Nanda - Misys Software Solutions,Bangalore
    Tuesday, July 27, 2010 12:43 PM
  • Hi to All!

    I need To Select All the Checkboxes to be Selected in the Gridview, with Single Event

    Thanks in Advance


     Are you using Windows Application or Web Application?

    Thanks,

    Paras Sanghani

     

    Tuesday, July 27, 2010 12:47 PM
  • Hope this will help you 

    protected void chkSelectAll_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox chk;
            foreach (GridViewRow rowItem in GridView1.Rows)
            {
                chk = (CheckBox)(rowItem.Cells[5].FindControl("chk1"));
                chk.Checked = ((CheckBox)sender).Checked;
            }
        }

    Tuesday, July 27, 2010 1:06 PM