启用分页时无法访问gridview的所有记录

Can't access all records of gridview when paging enable

我有一个包含复选框 (chkSelect) 的网格视图 (gvClient)。 我为同一个网格启用了分页,并且有很多数据要显示。 但我面临的问题是,在从 gridview 检索所有数据时,我只获取当前页面 gridview 数据。 我的代码:

foreach (GridViewRow gvrClient in gvClient.Rows)  // gvClient.Rows not giving all gridview rows
{
     cbSelect = (CheckBox)gvrClient.FindControl("chkSelect");
     if (cbSelect.Checked == true)
     {
        //Operations
     }
}

我在 google 上得到了以下解决方案可以使用,但它不起作用。

 gvClient.AllowPaging=false;
 gvClient.DataBind();
foreach (GridViewRow gvrClient in gvClient.Rows)  // gvClient.Rows not giving all gridview rows
{
    cbSelect = (CheckBox)gvrClient.FindControl("chkSelect");
    if (cbSelect.Checked == true)
    {
        //Operations
    }
 }
 gvClient.AllowPaging=true;
 gvClient.DataBind();

对此有任何帮助吗?

您无法在 C# 中访问所有页面。 顺便问一下,为什么要访问网格的完整数据?当您更改页面时,网格会再次重置。网格不维护页面状态数据。 您可以从已设置为该网格的数据源的 datatable/dataset 访问相同的数据..