how to clear selected check box in gridview when click clear button

Gani_tpt 2,046 Reputation points
2024-05-18T13:34:00.7266667+00:00

how to clear selected check box in gridview.

when i click clear button, all paging selected check box should clear by default.

How to do this..?

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,377 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,508 questions
0 comments No comments
{count} votes

Accepted answer
  1. Lan Huang-MSFT 27,956 Reputation points Microsoft Vendor
    2024-05-20T01:36:27.23+00:00

    Hi @Gani_tpt,

    This is the same way you saved all your page data before.

    If you want to operate on all pages, you can use this method.

    You can use the command below to browse all pages and browse all rows in each page. You can also get the current page before doing this and return there after looping through everything.

    protected void btnClear_Click(object sender, EventArgs e)
     {
         int a = gvCustomer.PageIndex;
         //Loop through All Pages
         for (int i = 0; i < gvCustomer.PageCount; i++)
         {
             //Set Page Index
             gvCustomer.SetPageIndex(i);
             //After Setting Page Index Loop through its Rows
             foreach (GridViewRow gvrow in gvCustomer.Rows)
             {
                 if (gvrow.RowType == DataControlRowType.DataRow)
                 {
                     CheckBox chk = (CheckBox)gvrow.FindControl("CheckBox1");
                     chk.Checked = false;
                 }
             }
         }
         gvCustomer.SetPageIndex(a);
     }
    

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful