ObjectDataSource.MaximumRowsParameterName Propiedad

Definición

Obtiene o establece el nombre del parámetro del método de recuperación de datos del objeto comercial utilizado para indicar el número de registros que se recuperan para admitir la paginación de origen de datos.

public:
 property System::String ^ MaximumRowsParameterName { System::String ^ get(); void set(System::String ^ value); };
public string MaximumRowsParameterName { get; set; }
member this.MaximumRowsParameterName : string with get, set
Public Property MaximumRowsParameterName As String

Valor de propiedad

Nombre del parámetro SelectMethod que se utiliza para indicar el número de registros que se recuperan. El valor predeterminado es "maximumRows".

Ejemplos

En los tres ejemplos siguientes se muestra una página web, una clase de página de código subyacente y una clase de acceso a datos que permite al usuario elegir cuántos registros se muestran en la página.

La página web contiene un ObjectDataSource control cuya EnablePaging propiedad está establecida en true. La SelectCountMethod propiedad se establece en el nombre de un método que devuelve el número total de registros de la consulta. La MaximumRowsParameterName propiedad y la StartRowIndexParameterName propiedad se establecen en los nombres de los parámetros que se usan en el método Select. La página también contiene un DropDownList control .

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>ObjectDataSource Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    How many rows to display on this page:<br />
    <asp:DropDownList 
          AutoPostBack="true" 
          ID="rowsToDisplay" 
          runat="server" 
          onselectedindexchanged="rowsToDisplay_SelectedIndexChanged">
        <asp:ListItem Value="5"></asp:ListItem>
        <asp:ListItem Value="10" Selected="True"></asp:ListItem>
        <asp:ListItem Value="20"></asp:ListItem>
    </asp:DropDownList> 
    
    <asp:ObjectDataSource 
        SelectCountMethod="GetEmployeeCount" 
        EnablePaging="true" 
        TypeName="CustomerLogic" 
        SelectMethod="GetSubsetOfEmployees"
        MaximumRowsParameterName="maxRows"
        StartRowIndexParameterName="startRows"
        ID="ObjectDataSource1" 
        runat="server">
    </asp:ObjectDataSource>
    
    <asp:GridView 
        DataSourceID="ObjectDataSource1" 
        AllowPaging="true" 
        ID="GridView1" 
        runat="server">
    </asp:GridView>
    
    </div>
    </form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    How many rows to display on this page:<br />
    <asp:DropDownList 
          AutoPostBack="true" 
          ID="rowsToDisplay" 
          runat="server" 
          onselectedindexchanged="rowsToDisplay_SelectedIndexChanged">
        <asp:ListItem Value="5"></asp:ListItem>
        <asp:ListItem Value="10" Selected="True"></asp:ListItem>
        <asp:ListItem Value="20"></asp:ListItem>
    </asp:DropDownList> 
    
    <asp:ObjectDataSource 
        SelectCountMethod="GetEmployeeCount" 
        EnablePaging="true" 
        TypeName="CustomerLogic" 
        SelectMethod="GetSubsetOfEmployees"
        MaximumRowsParameterName="maxRows"
        StartRowIndexParameterName="startRows"
        ID="ObjectDataSource1" 
        runat="server">
    </asp:ObjectDataSource>
    
    <asp:GridView 
        DataSourceID="ObjectDataSource1" 
        AllowPaging="true" 
        ID="GridView1" 
        runat="server">
    </asp:GridView>
    
    </div>
    </form>
</body>
</html>

En el segundo ejemplo se muestra un controlador para el ListControl.SelectedIndexChanged evento del DropDownList control. El código del controlador establece la PageSize propiedad en la selección del usuario.

protected void rowsToDisplay_SelectedIndexChanged(object sender, EventArgs e)
{
    GridView1.PageSize = int.Parse(rowsToDisplay.SelectedValue);
}
Protected Sub rowsToDisplay_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rowsToDisplay.SelectedIndexChanged
    GridView1.PageSize = Integer.Parse(rowsToDisplay.SelectedValue)
End Sub

En el tercer ejemplo se muestra la clase de acceso a datos que recupera datos de la tabla Customers. Incluye un método denominado GetSubsetOfEmployees, que se asigna a la SelectMethod propiedad del ObjectDataSource control . En el ejemplo también se incluye un método denominado GetEmployeeCount, que se asigna a la SelectCountMethod propiedad del ObjectDataSource control . La clase usa LINQ para consultar la tabla Customers. El ejemplo requiere una clase LINQ to SQL que representa la base de datos Northwind y la tabla Customers. Para obtener más información, vea How to: Create LINQ to SQL Classes in a Web Project.

public class CustomerLogic
{

    public List<Customer> GetSubsetOfEmployees(int startRows, int maxRows)
    {
        NorthwindDataContext ndc = new NorthwindDataContext();
        var customerQuery = 
            from c in ndc.Customers
            select c;

        return customerQuery.Skip(startRows).Take(maxRows).ToList<Customer>();
    }

    public int GetEmployeeCount()
    {
        object cachedCount = HttpRuntime.Cache["TotalEmployeeCount"];
        if (cachedCount != null)
        {
            return int.Parse(cachedCount.ToString());
        }
        else
        {
            NorthwindDataContext ndc = new NorthwindDataContext();
            var totalNumberQuery =
                from c in ndc.Customers
                select c;
            
            int employeeCount = totalNumberQuery.Count();
            HttpRuntime.Cache.Add("TotalEmployeeCount", employeeCount, null, DateTime.Now.AddMinutes(5), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
            return employeeCount;
        }
    }
}
Public Class CustomerLogic
    Public Function GetSubsetOfEmployees(ByVal startRows As Integer, ByVal maxRows As Integer) As List(Of Customer)

        Dim ndc As New NorthwindDataContext()
        Dim customerQuery = _
        From c In ndc.Customers _
            Select c

        Return customerQuery.Skip(startRows).Take(maxRows).ToList()
    End Function

    Public Function GetEmployeeCount() As Integer

        Dim cachedCount = HttpRuntime.Cache("TotalEmployeeCount")
        If cachedCount IsNot Nothing Then
            Return Integer.Parse(cachedCount.ToString())
        Else
            Dim ndc As New NorthwindDataContext()
            Dim totalNumberQuery = _
            From c In ndc.Customers _
                Select c

            Dim employeeCount = totalNumberQuery.Count()
            HttpRuntime.Cache.Add("TotalEmployeeCount", employeeCount, Nothing, DateTime.Now.AddMinutes(5), Cache.NoSlidingExpiration, CacheItemPriority.Normal, Nothing)
            Return employeeCount
        End If
    End Function
End Class

Comentarios

La MaximumRowsParameterName propiedad se usa para admitir la paginación del origen de datos. Para obtener información sobre cómo el control admite la ObjectDataSource paginación, vea EnablePaging.

La MaximumRowsParameterName propiedad delega a la MaximumRowsParameterName propiedad del ObjectDataSourceView objeto asociado al ObjectDataSource control .

Se aplica a

Consulte también