Export (0) Print
Expand All

LinqDataSourceStatusEventArgs.TotalRowCount Property

Gets the total number of rows in a data set from a data-retrieval operation.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

public int TotalRowCount { get; }

Property Value

Type: System.Int32
The total number of rows in a data set from the data retrieval operation; -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.

You use the TotalRowCount property to get the number of records in the data set during a data retrieval operation. Typically, you retrieve this property when you are displaying pages of data and want to show the total number of records.

When data is being paged, the value in the TotalRowCount property might be different from the actual number of rows that are returned by the query. This is because the query returns only the number of rows that are needed for that page of data.

The TotalRowCount property contains the number of records from a query only when it is accessed in an event handler for the Selected event. When the property is accessed from an event handler for the ContextCreated, Deleted, Inserted, or Updated event, the TotalRowCount property contains -1.

The value of the TotalRowCount property depends on the AutoPage property of the LinqDataSource control, and on the AllowPaging property of the data-bound control. The following table summarizes the possible values for the TotalRowCount property.

AutoPage Property of LinqDataSource control

AllowPaging Property of data-bound control

TotalRowCount property




Number of records for a query.

Data is automatically paged.



Number of records for a query.

Data is not paged.




Data is not paged.



The value that you assigned to the TotalRowCount property in the event handler for the Selecting event.

Data is paged according to the values that you specified when you customized paging.

The following example shows a Web page with a LinqDataSource control, a GridView control, and a Literal control. The LinqDataSource control defines an event handler for the Selected event.

<asp:Literal ID="Literal1" runat="server"></asp:Literal> Total Records
<br />

The following example shows the code for the event handler for the Selected event. The value of the TotalRowCount property is assigned to the Literal control.

protected void LinqDataSource1_Selected(object sender, LinqDataSourceStatusEventArgs e)
    Literal1.Text = e.TotalRowCount.ToString();

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft