The total number of rows in a GridView control using LinqDataSource and swap

I had a problem getting the total number of rows for items displayed in the Gridview, using Paging and with the LinqDataSource as the data source.

I tried several approaches:

protected void GridDataSource_Selected(object sender, LinqDataSourceStatusEventArgs e)  
{  
    totalLabel.Text = e.TotalRowCount.ToString();  
}

returns -1 every time.

protected void LinqDataSource1_Selected(object sender, LinqDataSourceStatusEventArgs e)  
{  
    System.Collections.Generic.List<country> lst  = e.Result as System.Collections.Generic.List<country>;  
    int count = lst.Count;  
}

gives me only the score for the current page, not the total.

Any other suggestions?

+3
source share
5 answers

The LinqDataSourceEventArgs returned in these events returns -1 in these cases:

-1, LinqDataSourceStatusEventArgs ; -1, , AutoPage true RetrieveTotalRowCount false.

- , , , , AutoPage AllowPage true, false.

, , Autopage false, AllowPaging true, .

+3

, AutoPage AllowPaging true. , RetrieveTotalRowCount true, ( , ).

-1.

, :

-1, LinqDataSourceStatusEventArgs ;

, . LinqDataSource, , . , . TotalRowCount, . , , -1.

0

.

protected void LinqDataSourcePoints_Selected ( , LinqDataSourceStatusEventArgs e)   {       totalRecords = (e.Result as List).Count;   }

: 1- e.Result 2- .

.

0

, .

  protected void LinqDataSource1_Selecting(object sender, LinqDataSourceStatusEventArgs e)
        {
           System.Collections.Generic.List<country> lst  = e.Result as System.Collections.Generic.List<country>;

           int count = lst.Count;
        }

make sure your event is " Select "

0
source

Source: https://habr.com/ru/post/1696537/


All Articles