ObjectDataSource.EnablePaging プロパティ
アセンブリ: System.Web (system.web.dll 内)

Dim instance As ObjectDataSource Dim value As Boolean value = instance.EnablePaging instance.EnablePaging = value
/** @property */ public boolean get_EnablePaging () /** @property */ public void set_EnablePaging (boolean value)
データ ソース コントロールが取得したデータを使用するページングをサポートしている場合は true。それ以外の場合は false。

ObjectDataSource コントロールによるページングは、ObjectDataSource の EnablePaging、StartRowIndexParameterName、MaximumRowsParameterName、SelectCountMethod の各プロパティを設定し、適切なパラメータでビジネス オブジェクトの選択メソッドを定義することによって処理されます。EnablePaging プロパティを true に設定すると、SelectParameters コレクションに、要求された最初の行と要求された行数に対応する 2 つのパラメータが追加されます。この 2 つのパラメータには、StartRowIndexParameterName プロパティと MaximumRowsParameterName プロパティで定義された名前が付けられます。Select メソッドは、指定されたインデックス位置で始まる要求された行数を返します。データは、ページ サイズによって均等に分割されない場合があるため、最後のページには行がほとんど含まれていない場合があります。したがって、要求された行数は、実際には返される最大行数です。
関連付けられたデータ バインド コントロールでページングが有効になっている場合、データ バインド コントロールは、必要とされる開始インデックスと行数を使用して、Select メソッドを呼び出します。また、SelectCountMethod プロパティが設定されている場合、データ バインド コントロールは、ページャ コントロールを表示する前にこのメソッドを呼び出します。たとえば、GridView コントロールでページ サイズが 5 の状態でページングが有効になっており、SelectCountMethod プロパティで指定されたメソッドが 20 を返す場合、4 ページ分だけページャに表示されます。
EnablePaging プロパティは、ObjectDataSourceView オブジェクトの EnablePaging プロパティに処理を代行させます。

このセクションには、2 つのコード例が含まれています。1 つ目のコードでは、ページングを有効にする型を実装する方法を示します。2 つ目のコード例では、ObjectDataSource クラスのインスタンスを作成し、プロパティを設定する方法を示します。
ページングを有効にする型を実装する方法を次のコード例に示します。PagingData.Select メソッドは、startRowIndex および maximumRows の 2 つのパラメータを受け取ります。また、PagingData クラスは、データ内の行の総数を返す SelectCount という名前のメソッドを定義します。PagingData クラスのコードを次に示します。
Imports System Imports System.Data Imports System.Configuration Imports System.Web Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts Imports System.Web.UI.HtmlControls Namespace Samples.AspNet.VB Public Class PagingData Public Sub New() End Sub Shared table As DataTable Private Function CreateData() As DataTable table = New DataTable() table.Columns.Add("Name", GetType(String)) table.Columns.Add("Number", GetType(Integer)) Return table End Function Public Function SelectMethod(ByVal startRowIndex As Integer, ByVal maximumRows As Integer) As DataTable CreateData() Dim current As Integer For i As Integer = 0 To maximumRows - 1 current = i + startRowIndex table.Rows.Add(New Object() {"Number" + current.ToString(), current}) Next Return table End Function Public Function SelectCount() As Integer Return 20 End Function Public Function Insert(ByVal newRecord As NewData) As Integer table.Rows.Add(New Object() {newRecord.Name, newRecord.Number}) Return 1 End Function End Class Public Class NewData Private nameValue As String Private numberValue As Integer Public Property Name() As String Get Return nameValue End Get Set(ByVal value As String) nameValue = value End Set End Property Public Property Number() As Integer Get Return numberValue End Get Set(ByVal value As Integer) numberValue = value End Set End Property End Class End Namespace
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; namespace Samples.AspNet.CS { public class PagingData { public PagingData() { } static DataTable table; private DataTable CreateData() { table = new DataTable(); table.Columns.Add("Name", typeof(string)); table.Columns.Add("Number", typeof(int)); return table; } public DataTable SelectMethod(int startRowIndex, int maximumRows) { CreateData(); int current; for (int i = 0; i < maximumRows; i++) { current = i + startRowIndex; table.Rows.Add(new object[] { "Number" + current.ToString(), current }); } return table; } public int SelectCount() { return 20; } public int Insert(NewData newRecord) { table.Rows.Add(new object[] { newRecord.Name, newRecord.Number }); return 1; } } public class NewData { private string nameValue; private int numberValue; public string Name { get { return nameValue; } set { nameValue = value; } } public int Number { get { return numberValue; } set { numberValue = value; } } } }
ObjectDataSource クラスのインスタンスを作成し、ページングに関する次のプロパティを設定する方法を次のコード例に示します。
MaximumRowsParameterName プロパティと StartRowIndexParameterName プロパティの値は、それぞれ maximumRows および startRowIndex という既定値として残されます。
<%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <script runat="server"> </script> <html > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" AllowPaging="True" DataSourceID="ObjectDataSource1" PageSize="5"> </asp:GridView> <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" EnablePaging="True" SelectCountMethod="SelectCount" SelectMethod="SelectMethod" TypeName="Samples.AspNet.VB.PagingData"> </asp:ObjectDataSource> </div> </form> </body> </html>
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <script runat="server"> </script> <html > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" AllowPaging="True" DataSourceID="ObjectDataSource1" PageSize="5"> </asp:GridView> <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" EnablePaging="True" SelectCountMethod="SelectCount" SelectMethod="SelectMethod" TypeName="Samples.AspNet.CS.PagingData"> </asp:ObjectDataSource> </div> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からObjectDataSource.EnablePaging プロパティを検索する場合は、下記のリンクをクリックしてください。

- ObjectDataSource.EnablePaging プロパティのページへのリンク