<p>I'm having a problem obtaining the total row count for items displayed in a Gridview using Paging and with a LinqDataSource as the source of data.</p>

<p>I've tried several approaches:</p>

<pre><code>protected void GridDataSource_Selected(object sender, LinqDataSourceStatusEventArgs e)  
{  
    totalLabel.Text = e.TotalRowCount.ToString();  
}
</code></pre>

<p>returns -1 every time.</p>

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

<p>only gives me the count for the current page, and not the total.</p>

<p>Any other suggestions?</p>

The LinqDataSourceEventArgs returned in those events return -1 on these occasions:
-1 if the LinqDataSourceStatusEventArgs object was created during a data modification operation; -1 if you enabled customized paging by setting AutoPage to true and by setting RetrieveTotalRowCount to false.
Check here for more information
- the table towards the bottom, shows different properties to set to get the rowcount back, but it looks like you either have to set AutoPage and AllowPage properties to either both true or both false.
Judging by the table in the link above and the example you provide you have Autopage set to false, but AllowPaging set to true, therefore it is returning the amount of rows in the page.
HTH