ObjectDataSource.EnablePaging 속성

정의

데이터 소스 컨트롤에서 검색된 데이터 집합을 통해 페이징을 지원하는지 여부를 나타내는 값을 가져오거나 설정합니다.

public:
 property bool EnablePaging { bool get(); void set(bool value); };
public bool EnablePaging { get; set; }
member this.EnablePaging : bool with get, set
Public Property EnablePaging As Boolean

속성 값

데이터 소스 컨트롤에서 검색된 데이터에 대해 페이징을 지원하면 true이고, 그렇지 않으면 false입니다.

예제

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

웹 페이지에는 ObjectDataSource 컨트롤 EnablePaging 속성이 true합니다. SelectCountMethod 쿼리에서 레코드의 총 수를 반환 하는 메서드의 이름으로 설정 합니다. 합니다 MaximumRowsParameterName 속성 및 StartRowIndexParameterName 속성 선택 메서드에서 사용 되는 매개 변수의 이름으로 설정 됩니다. 페이지는 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 테이블에서 데이터를 검색 하는 데이터 액세스 클래스를 보여 줍니다. 라는 메서드를 포함 GetSubsetOfEmployees에 할당 되는 SelectMethod 의 속성을 ObjectDataSource 컨트롤입니다. 예제에는 또한 라는 메서드 GetEmployeeCount에 할당 되는 SelectCountMethod 의 속성은 ObjectDataSource 컨트롤입니다. LINQ를 사용 하 여 Customers 테이블을 쿼리 하는 클래스입니다. 이 예제에서는 LINQ to SQL 클래스 Northwind 데이터베이스와 Customers 테이블을 나타내는 필요 합니다. 자세한 내용은 방법: 만들 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

설명

페이징 합니다 ObjectDataSource 컨트롤을 설정 하 여 처리 됩니다는 EnablePaging, StartRowIndexParameterName, MaximumRowsParameterName, 및 SelectCountMethod 의 속성을 ObjectDataSource 적절 한 매개 변수를 사용 하 여 비즈니스 개체에서 선택 메서드를 정의 하 고 합니다. 경우는 EnablePaging 속성이 true, SelectParameters 컬렉션은 요청 되는 첫 번째 행 및 요청 된 행의 수에 대 한 두 개의 추가 매개 변수를 포함 합니다. 이러한 두 매개 변수 이름이 정의 된 대로 합니다 StartRowIndexParameterNameMaximumRowsParameterName 속성입니다. Select 메서드 요청된 수가 지정된 된 인덱스에서 시작 하는 행을 반환 해야 합니다. 데이터 페이지 크기에 따라 균등 하 게 나누지 수 있으므로 마지막 페이지 적은 수의 행을 포함할 수 있습니다. 따라서 요청 된 행의 수는 실제로 반환 되는 행의 최대 수 있습니다.

데이터 바인딩된 컨트롤을 호출 하는 페이징 연결된 된 데이터 바인딩된 컨트롤에 사용 되는 경우는 Select 요청 된 행의 수와 시작 인덱스를 사용 하 여 메서드. 또한 경우는 SelectCountMethod 속성이 설정 되 면 데이터 바인딩된 컨트롤의 페이저 컨트롤을 렌더링 하기 전에 메서드를 호출 합니다. 예를 들어 경우는 GridView 컨트롤에서 페이징을 사용 하 여 지정 된 메서드와 5, 페이지 크기가 SelectCountMethod 20을 반환 하는 속성, 호출기에 4 개의 페이지만 표시 됩니다.

EnablePaging 에 위임 하는 속성을 EnablePaging 의 속성을 ObjectDataSourceView 개체.

적용 대상

추가 정보