DataGrid.AllowCustomPaging 속성

정의

사용자 지정 페이징의 활성화 여부를 나타내는 값을 가져오거나 설정합니다.

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

속성 값

사용자 지정 페이징이 활성화되면 true이고, 그렇지 않으면 false입니다. 기본값은 false입니다.

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 AllowCustomPaging 속성 사용자 지정 페이징을 사용 하도록 설정 합니다.

<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >

   <script runat="server">

      // Normally, an entire data source is loaded in the DataGrid control, 
      // which can take up a lot of resources. This example uses custom 
      // paging, which loads only the segment of data needed to fill a
      // single page. In order to query for the appropriate segment of
      // data, the index of the first item displayed on a page must be
      // tracked as the user navigates between pages.
      int startIndex = 0;

      ICollection CreateDataSource() 
      {

         // Create sample data for the DataGrid control.
         DataTable dt = new DataTable();
         DataRow dr;

         // Define the columns of the table.
         dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
         dt.Columns.Add(new DataColumn("StringValue", typeof(string)));
         dt.Columns.Add(new DataColumn("DateTimeValue", typeof(string)));
         dt.Columns.Add(new DataColumn("BoolValue", typeof(bool)));

         // Populate the table with sample values. When using custom paging,
         // a query should only return enough data to fill a single page, 
         // beginning at the start index.
         for (int i = startIndex; i < (startIndex + MyDataGrid.PageSize); i++) 
         {
             dr = dt.NewRow();

             dr[0] = i;
             dr[1] = "Item " + i.ToString();
             dr[2] = DateTime.Now.ToShortDateString();
             dr[3] = (i % 2 != 0) ? true : false;

             dt.Rows.Add(dr);
         }

         DataView dv = new DataView(dt);
         return dv;

      }

      void Page_Load(Object sender, EventArgs e) 
      {

         // Load sample data only once, when the page is first loaded.
         if (!IsPostBack) 
         {

            // Set the virtual item count, which specifies the total number
            // items displayed in the DataGrid control when custom paging
            // is used.
            MyDataGrid.VirtualItemCount = 200;

            // Retrieve the segment of data to display on the page from the
            // data source and bind it to the DataGrid control.
            BindGrid();

         }

      }

      void MyDataGrid_Page(Object sender, DataGridPageChangedEventArgs e) 
      {

         // For the DataGrid control to navigate to the correct page when
         // paging is allowed, the CurrentPageIndex property must be updated
         // programmatically. This process is usually accomplished in the
         // event-handling method for the PageIndexChanged event.

         // Set CurrentPageIndex to the page the user clicked.
         MyDataGrid.CurrentPageIndex = e.NewPageIndex;

         // Calculate the index of the first item to display on the page 
         // using the current page index and the page size.
         startIndex = MyDataGrid.CurrentPageIndex * MyDataGrid.PageSize;

         // Retrieve the segment of data to display on the page from the 
         // data source and bind it to the DataGrid control.
         BindGrid();

      }

      void BindGrid() 
      {

         MyDataGrid.DataSource = CreateDataSource();
         MyDataGrid.DataBind();

      }

   </script>

<head runat="server">
    <title> DataGrid Custom Paging Example </title>
</head>
<body>

   <form id="form1" runat="server">
 
      <h3> DataGrid Custom Paging Example </h3>

      <asp:DataGrid id="MyDataGrid" 
           AllowCustomPaging="True" 
           AllowPaging="True" 
           PageSize="10" 
           OnPageIndexChanged="MyDataGrid_Page" 
           runat="server">

         <HeaderStyle BackColor="Navy" 
                      ForeColor="White" 
                      Font-Bold="True" />

         <PagerStyle Mode="NumericPages" 
                     HorizontalAlign="Right" />

      </asp:DataGrid>

   </form>

</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >

   <script runat="server">

      ' Normally, an entire data source is loaded in the DataGrid control, 
      ' which can take up a lot of resources. This example uses custom 
      ' paging, which loads only the segment of data needed to fill a
      ' single page. In order to query for the appropriate segment of
      ' data, the index of the first item displayed on a page must be
      ' tracked as the user navigates between pages.
      Dim startIndex As Integer = 0

      Function CreateDataSource() As ICollection 

         ' Create sample data for the DataGrid control.
         Dim dt As DataTable = New DataTable()
         Dim dr As DataRow

         ' Define the columns of the table.
         dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
         dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
         dt.Columns.Add(New DataColumn("DateTimeValue", GetType(String)))
         dt.Columns.Add(New DataColumn("BoolValue", GetType(Boolean)))

         ' Populate the table with sample values. When using custom paging,
         ' a query should only return enough data to fill a single page, 
         ' beginning at the start index.
         Dim i As Integer         

         For i = startIndex To ((startIndex + MyDataGrid.PageSize) - 1) 

             dr = dt.NewRow()

             dr(0) = i
             dr(1) = "Item " & i.ToString()
             dr(2) = DateTime.Now.ToShortDateString()
             If (i Mod 2 <> 0) Then
                dr(3) = True
             Else
                dr(3) = False
             End If

             dt.Rows.Add(dr)

         Next i

         Dim dv As DataView = New DataView(dt)
         Return dv

      End Function

      Sub Page_Load(sender As Object, e As EventArgs) 

         ' Load sample data only once, when the page is first loaded.
         If Not IsPostBack Then 

            ' Set the virtual item count, which specifies the total number
            ' items displayed in the DataGrid control when custom paging
            ' is used.
            MyDataGrid.VirtualItemCount = 200

            ' Retrieve the segment of data to display on the page from the 
            ' data source and bind it to the DataGrid control.
            BindGrid()

         End If

      End Sub

      Sub MyDataGrid_Page(sender as Object, e As DataGridPageChangedEventArgs) 

         ' For the DataGrid control to navigate to the correct page when
         ' paging is allowed, the CurrentPageIndex property must be updated
         ' programmatically. This process is usually accomplished in the
         ' event-handling method for the PageIndexChanged event.

         ' Set CurrentPageIndex to the page the user clicked.
         MyDataGrid.CurrentPageIndex = e.NewPageIndex

         ' Calculate the index of the first item to display on the page 
         ' using the current page index and the page size.
         startIndex = MyDataGrid.CurrentPageIndex * MyDataGrid.PageSize

         ' Retrieve the segment of data to display on the page from the 
         ' data source and bind it to the DataGrid control.
         BindGrid()

      End Sub

      Sub BindGrid() 

         MyDataGrid.DataSource = CreateDataSource()
         MyDataGrid.DataBind()

      End Sub

   </script>

<head runat="server">
    <title> DataGrid Custom Paging Example </title>
</head>
<body>

   <form id="form1" runat="server">
 
      <h3> DataGrid Custom Paging Example </h3>

      <asp:DataGrid id="MyDataGrid" 
           AllowCustomPaging="True" 
           AllowPaging="True" 
           PageSize="10" 
           OnPageIndexChanged="MyDataGrid_Page" 
           runat="server">

         <HeaderStyle BackColor="Navy" 
                      ForeColor="White" 
                      Font-Bold="True" />

         <PagerStyle Mode="NumericPages" 
                     HorizontalAlign="Right" />

      </asp:DataGrid>

   </form>

</body>
</html>

설명

페이징의 내용을 표시할 수는 DataGrid 페이지 세그먼트의 컨트롤입니다. 페이지에 있는 항목의 수에 의해 결정 되는 PageSize 속성입니다. 없는 값을 지정 하는 경우는 PageSize 속성을 DataGrid 10 개 항목을 페이지에 표시 됩니다.

일반적으로의 모든 행을 포함 하는 데이터 소스를 DataGrid 컨트롤이 로드 될 때마다는 DataGrid 컨트롤이 다른 페이지로 이동 합니다. 이 하면 데이터 원본이 매우 큰 경우 리소스를 많이 사용할 수 있습니다. 사용자 지정 페이징을 사용 하면 단일 페이지를 표시 하는 데 필요한 데이터의 세그먼트만 로드할 수 있습니다.

페이징을 사용 하도록 사용자 지정을 모두를 설정 합니다 AllowPaging 하 고 AllowCustomPaging 속성을 true입니다. 다음으로 처리 하는 코드를 제공 합니다 PageIndexChanged 이벤트입니다.

에 대 한 일반적인 논리는 PageIndexChanged 이벤트 처리기는 먼저 설정 하는 CurrentPageIndex 속성을 표시 하려는 페이지의 인덱스입니다.

참고

이벤트 처리기는 수신 된 DataGridPageChangedEventArgs 개체를 매개 변수로 합니다. 사용할 수는 NewPageIndex 속성의 페이지 선택 요소에서 사용자가 선택한 페이지의 인덱스를 확인 하려면이 매개 변수는 DataGrid 컨트롤입니다.

다음으로 단일 페이지에 표시 되 고 사용 하 여 데이터를 포함 하는 데이터 소스를 만듭니다는 DataBind 데이터를 바인딩하는 메서드는 DataGrid 제어 합니다.

참고

데이터의 세그먼트만 로드 되기 때문에 설정 해야 합니다 VirtualItemCount 속성에 있는 항목의 총 수를 DataGrid 컨트롤. 이렇게 하면 컨트롤에서 모든 항목을 표시 하는 데 필요한 페이지의 총 수를 확인 하는 DataGrid 제어 합니다. 이 속성은 일반적으로 프로그래밍 방식으로 설정 되 면에 있는 항목의 총 수를 DataGrid 컨트롤 결정 됩니다.

사용 하 여 페이징이 활성화 된 경우는 AllowCustomPaging 속성이 false, DataGrid 컨트롤 데이터 소스의 모든 항목을 포함 하는 것으로 가정 합니다. DataGrid 컨트롤이 지정 된 페이지 인덱스를 기준으로 표시 된 페이지에 있는 항목의 인덱스를 계산 합니다 CurrentPageIndex 속성과 지정 된 페이지에는 항목 수를 PageSize 속성.

경우는 AllowCustomPaging 속성이로 설정 되어 true, DataGrid 컨트롤 데이터 소스에만 기준으로 항목을 포함 하는 것으로 가정 합니다 VirtualItemCount 속성. 지정 된 항목 개수까지 모든 항목을 PageSize 속성이 표시 됩니다.

적용 대상

추가 정보