LinqDataSourceStatusEventArgs.TotalRowCount 属性

定义

获取数据检索操作过程中在某个数据集中检索的总行数。Gets the total number of rows in a data set from a data-retrieval operation.

public:
 property int TotalRowCount { int get(); };
public int TotalRowCount { get; }
member this.TotalRowCount : int
Public ReadOnly Property TotalRowCount As Integer

属性值

Int32

数据检索操作过程中在某个数据集中检索的总行数;如果 LinqDataSourceStatusEventArgs 对象是在数据修改操作过程中创建的,则为 -1;如果通过将 AutoPage 设置为 true 并将 RetrieveTotalRowCount 设置为 false 启用了自定义分页,则为 -1。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.

示例

下面的示例演示包含 LinqDataSource 控件、 GridView 控件和控件的网页 LiteralThe following example shows a Web page with a LinqDataSource control, a GridView control, and a Literal control. LinqDataSource控件定义事件的事件处理程序 SelectedThe LinqDataSource control defines an event handler for the Selected event.

<asp:Literal ID="Literal1" runat="server"></asp:Literal> Total Records
<br />
<asp:LinqDataSource 
  AutoPage="true"
  ID="LinqDataSource1" 
  runat="server" 
  ContextTypeName="ExampleDataContext" 
  TableName="Customers" 
  onselected="LinqDataSource1_Selected">
</asp:LinqDataSource>
<asp:GridView 
  ID="GridView1" 
  runat="server" 
  AllowPaging="true" 
  AutoGenerateColumns="True" 
  DataKeyNames="CustomerID" 
  DataSourceID="LinqDataSource1">
</asp:GridView>
<asp:Literal ID="Literal1" runat="server"></asp:Literal> Total Records
<br />
<asp:LinqDataSource 
  AutoPage="true"
  ID="LinqDataSource1" 
  runat="server" 
  ContextTypeName="ExampleDataContext" 
  TableName="Customers">
</asp:LinqDataSource>
<asp:GridView 
  ID="GridView1" 
  runat="server" 
  AllowPaging="true" 
  AutoGenerateColumns="True" 
  DataKeyNames="CustomerID" 
  DataSourceID="LinqDataSource1">
</asp:GridView>

下面的示例演示事件的事件处理程序的代码 SelectedThe following example shows the code for the event handler for the Selected event. 将属性的值 TotalRowCount 分配给 Literal 控件。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();
}
Protected Sub LinqDataSource1_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceStatusEventArgs) Handles LinqDataSource1.Selected
    Literal1.Text = e.TotalRowCount.ToString()
End Sub

注解

TotalRowCount 数据检索操作过程中,可以使用属性来获取数据集中的记录数。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.

数据分页时,属性中的值 TotalRowCount 可能与查询返回的实际行数不同。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.

TotalRowCount仅当在事件的事件处理程序中对其进行访问时,此属性才包含查询中的记录数 SelectedThe TotalRowCount property contains the number of records from a query only when it is accessed in an event handler for the Selected event. 当从、、或事件的事件处理程序访问该属性时 ContextCreated Deleted Inserted Updated ,该属性将 TotalRowCount 包含-1。When the property is accessed from an event handler for the ContextCreated, Deleted, Inserted, or Updated event, the TotalRowCount property contains -1.

属性的值 TotalRowCount 取决于 AutoPage 控件的属性 LinqDataSourceAllowPaging 数据绑定控件的属性。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. 下表汇总了属性的可能值 TotalRowCountThe following table summarizes the possible values for the TotalRowCount property.

LinqDataSource 控件的 "自动页" 属性AutoPage Property of LinqDataSource control 数据绑定控件的 AllowPaging 属性AllowPaging Property of data-bound control TotalRowCount 属性TotalRowCount property 业务成效Outcome
true true 查询的记录数。Number of records for a query. 数据自动分页。Data is automatically paged.
false false 查询的记录数。Number of records for a query. 数据未分页。Data is not paged.
true false -1-1 数据未分页。Data is not paged.
false true 分配给 TotalRowCount 事件的事件处理程序中的属性的值 SelectingThe 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.

适用于