다음을 통해 공유


ObjectDataSource.MaximumRowsParameterName 속성

정의

데이터 원본 페이징 지원을 위해 검색할 레코드 수를 나타내는 데 사용되는 비즈니스 개체 데이터 검색 메서드 매개 변수의 이름을 가져오거나 설정합니다.

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

속성 값

검색할 SelectMethod 레코드 수를 나타내는 데 사용되는 매개 변수의 이름입니다. 기본값은 "maximumRows"입니다.

예제

다음 세 가지 예제에서는 웹 페이지, 코드 숨김 페이지 클래스 및 사용자가 페이지에 표시되는 레코드 수를 선택할 수 있는 데이터 액세스 클래스를 보여 줍니다.

웹 페이지에는 속성이 ObjectDataSource .로 설정된 컨트롤 EnablePaging 이 포함되어 있습니다 true. 이 SelectCountMethod 속성은 쿼리의 총 레코드 수를 반환하는 메서드의 이름으로 설정됩니다. MaximumRowsParameterName 속성과 StartRowIndexParameterName 속성은 Select 메서드에 사용되는 매개 변수의 이름으로 설정됩니다. 페이지에는 컨트롤도 포함되어 있습니다 DropDownList .

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

두 번째 예제에서는 컨트롤의 ListControl.SelectedIndexChanged 이벤트에 대 한 처리기를 보여 있습니다 DropDownList . 처리기의 코드는 속성을 사용자의 선택 영역으로 설정합니다 PageSize .

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

세 번째 예제에서는 Customers 테이블에서 데이터를 검색하는 데이터 액세스 클래스를 보여 줍니다. 여기에는 컨트롤의 속성에 SelectMethod 할당된 명명GetSubsetOfEmployees된 메서드가 ObjectDataSource 포함됩니다. 이 예제에는 컨트롤의 속성에 SelectCountMethod 할당된 명명GetEmployeeCount된 메서드도 포함되어 있습니다ObjectDataSource. 클래스는 LINQ를 사용하여 Customers 테이블을 쿼리합니다. 이 예제에서는 Northwind 데이터베이스 및 Customers 테이블을 나타내는 LINQ to SQL 클래스가 필요합니다. 자세한 내용은 방법: 웹 프로젝트에서 LINQ to SQL 클래스 만들기를 참조하세요.

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

설명

MaximumRowsParameterName 속성은 데이터 원본 페이징을 지원하는 데 사용됩니다. 컨트롤에서 페이징을 지원하는 방법에 대한 자세한 내용은 다음을 ObjectDataSource 참조하세요 EnablePaging.

MaximumRowsParameterName 컨트롤과 MaximumRowsParameterName 연결된 개체의 속성에 ObjectDataSourceView 속성이 위임됩니다ObjectDataSource.

적용 대상

추가 정보