ObjectDataSource.MaximumRowsParameterName Propriedade

Definição

Obtém ou define o nome do parâmetro de método de recuperação de dados do objeto comercial usado para indicar o número de registros a serem recuperados para suporte à paginação de fonte de dados.

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 da propriedade

O nome do parâmetro SelectMethod que é usado para indicar o número de registros a recuperar. O padrão é "maximumRows".

Exemplos

Os três exemplos a seguir mostram uma página da Web, uma classe de página code-behind e uma classe de acesso a dados que permitem ao usuário escolher quantos registros são exibidos na página.

A página da Web contém um ObjectDataSource controle cuja EnablePaging propriedade está definida como true. A SelectCountMethod propriedade é definida como o nome de um método que retorna o número total de registros na consulta. A MaximumRowsParameterName propriedade e a StartRowIndexParameterName propriedade são definidas como os nomes dos parâmetros usados no método Select. A página também contém um DropDownList controle .

<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>

O segundo exemplo mostra um manipulador para o ListControl.SelectedIndexChanged evento do DropDownList controle . O código no manipulador define a PageSize propriedade como a seleção do usuário.

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

O terceiro exemplo mostra a classe de acesso a dados que recupera dados da tabela Customers. Ele inclui um método chamado GetSubsetOfEmployees, que é atribuído à SelectMethod propriedade do ObjectDataSource controle . O exemplo também inclui um método chamado GetEmployeeCount, que é atribuído à SelectCountMethod propriedade do ObjectDataSource controle . A classe usa LINQ para consultar a tabela Customers. O exemplo requer uma classe LINQ to SQL que representa o banco de dados Northwind e a tabela Customers. Para obter mais informações, consulte Como criar classes LINQ to SQL em um projeto Web.

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

Comentários

A MaximumRowsParameterName propriedade é usada para dar suporte à paginação da fonte de dados. Para obter informações sobre como a paginação é compatível com o ObjectDataSource controle , consulte EnablePaging.

A MaximumRowsParameterName propriedade delega à MaximumRowsParameterName propriedade do ObjectDataSourceView objeto associado ao ObjectDataSource controle .

Aplica-se a

Confira também