DataGrid.AllowCustomPaging プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DataGrid.AllowCustomPaging プロパティの意味・解説 

DataGrid.AllowCustomPaging プロパティ

カスタム ページング有効にするかどうかを示す値を取得または設定します

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Overridable Property
 AllowCustomPaging As Boolean
Dim instance As DataGrid
Dim value As Boolean

value = instance.AllowCustomPaging

instance.AllowCustomPaging = value
public virtual bool AllowCustomPaging { get;
 set; }
public:
virtual property bool AllowCustomPaging {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_AllowCustomPaging ()

/** @property */
public void set_AllowCustomPaging (boolean
 value)
public function get AllowCustomPaging
 () : boolean

public function set AllowCustomPaging
 (value : boolean)

プロパティ
カスタム ページング有効な場合trueそれ以外場合false既定値false です。

解説解説

ページングにより、ページ セグメントに DataGrid コントロール内容表示できますページ項目数は、PageSize プロパティによって決まりますPageSize プロパティの値を指定しなかった場合DataGrid1 ページ10 項目を表示します

通常DataGrid コントロールすべての行を格納しているデータ ソースは、その DataGrid コントロール別のページ移動するたびに読み込まれます。データ ソース大き場合は、この動作によって多量リソース利用されます。カスタム ページングでは、1 ページ表示必要なデータセグメントだけが読み込まれます。

カスタム ページング有効にするには、AllowPaging プロパティAllowCustomPaging プロパティtrue設定します続いて PageIndexChanged イベント処理するコード作成します

PageIndexChanged イベント ハンドラ典型的なロジックは、まず CurrentPageIndex プロパティ表示するページインデックス設定します

メモメモ

イベント ハンドラは、DataGridPageChangedEventArgs オブジェクトパラメータとして受け取ります。このパラメータの NewPageIndex プロパティ使用してDataGrid コントロールページ選択要素ユーザー選択したページインデックス確認します

続いて1 ページ表示するデータ格納されているデータ ソース作成し、DataBind メソッド使用してデータDataGrid コントロール連結します。

メモメモ

データ1 つセグメントだけが読み込まれるため、VirtualItemCount プロパティDataGrid コントロールの項目の合計数に設定する必要があります。この設定により、DataGrid コントロールが、内部の項目をすべて表示するために必要なページ合計数を判断できるようになります。このプロパティは、通常DataGrid コントロール内の合計項目数決定されたときにプログラムによって自動的に設定されます。

AllowCustomPaging プロパティfalse設定されページング有効になっている場合DataGrid コントロール表示する項目のすべてがデータ ソース格納されているものと見なします。DataGrid コントロールは、CurrentPageIndex プロパティ指定されページ インデックスPageSize プロパティ指定されページ項目数基づいて表示されページ上にある項目のインデックス計算します

AllowCustomPaging プロパティtrue設定されている場合DataGrid コントロールVirtualItemCount プロパティ指定した項目だけデータ ソース格納されていると見なします。PageSize プロパティ指定した項目数までのすべての項目が表示されます。

使用例使用例

AllowCustomPaging プロパティ使用してカスタム ページング有効にする方法次のコード例示します

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

<html>

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

<body>

   <form 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="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>

<html>

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

<body>

   <form 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 クラス
DataGrid メンバ
System.Web.UI.WebControls 名前空間
VirtualItemCount
CurrentPageIndex
PageSize



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「DataGrid.AllowCustomPaging プロパティ」の関連用語

DataGrid.AllowCustomPaging プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DataGrid.AllowCustomPaging プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS