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

<TemplateContainerAttribute(GetType(GridViewRow))> _ Public Overridable Property PagerTemplate As ITemplate
Dim instance As GridView Dim value As ITemplate value = instance.PagerTemplate instance.PagerTemplate = value
[TemplateContainerAttribute(typeof(GridViewRow))] public virtual ITemplate PagerTemplate { get; set; }
[TemplateContainerAttribute(typeof(GridViewRow))] public: virtual property ITemplate^ PagerTemplate { ITemplate^ get (); void set (ITemplate^ value); }
/** @property */ public ITemplate get_PagerTemplate () /** @property */ public void set_PagerTemplate (ITemplate value)
public function get PagerTemplate () : ITemplate public function set PagerTemplate (value : ITemplate)
ページ行のカスタム コンテンツを含んだ System.Web.UI.ITemplate。既定値は null で、このプロパティが設定されていないことを示します。

ページ行は、ページング機能が有効になっている場合 (AllowPaging が true に設定されている場合) に、GridView コントロールに表示されます。ページ行には、ユーザーがコントロール内の別のページに移動できるようにするコントロールが含まれています。組み込みのページ行ユーザー インターフェイス (UI) を使用する代わりに、PagerTemplate プロパティを設定して、独自の UI を定義できます。
![]() |
---|
ページ行のカスタム テンプレートを指定するには、最初に <PagerTemplate> タグを GridView コントロールの開始タグと終了タグの間に配置します。その後、<PagerTemplate> の開始タグと終了タグの間に、テンプレートの内容のリストを記述できます。ページ行の外観を制御するには、PagerStyle プロパティを使用します。
通常、ページング操作を実行するために、ページャ テンプレートにボタン コントロールが追加されます。GridView コントロールは、CommandName プロパティが "Page" に設定されているボタン コントロールがクリックされた場合に、ページング操作を実行します。ボタンの CommandArgument プロパティによって、実行するページング操作の種類が決まります。GridView コントロールでサポートされるコマンド引数値の一覧を次の表に示します。

ユーザーが DropDownList コントロールを使用して GridView コントロール内を移動できるようにするカスタム ページャ テンプレートを作成する方法を次のコード例に示します。
<%@ Page language="VB" %> <script runat="server"> Sub PageDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) ' Retrieve the pager row. Dim pagerRow As GridViewRow = CustomersGridView.BottomPagerRow ' Retrieve the PageDropDownList DropDownList from the bottom pager row. Dim pageList As DropDownList = CType(pagerRow.Cells(0).FindControl("PageDropDownList"), DropDownList) ' Set the PageIndex property to display that page selected by the user. CustomersGridView.PageIndex = pageList.SelectedIndex End Sub Sub CustomersGridView_DataBound(ByVal sender As Object, ByVal e As EventArgs) ' Retrieve the pager row. Dim pagerRow As GridViewRow = CustomersGridView.BottomPagerRow ' Retrieve the DropDownList and Label controls from the row. Dim pageList As DropDownList = CType(pagerRow.Cells(0).FindControl("PageDropDownList"), DropDownList) Dim pageLabel As Label = CType(pagerRow.Cells(0).FindControl("CurrentPageLabel"), Label) If Not pageList Is Nothing Then ' Create the values for the DropDownList control based on ' the total number of pages required to display the data ' source. Dim i As Integer For i = 0 To CustomersGridView.PageCount - 1 ' Create a ListItem object to represent a page. Dim pageNumber As Integer = i + 1 Dim item As ListItem = New ListItem(pageNumber.ToString()) ' If the ListItem object matches the currently selected ' page, flag the ListItem object as being selected. Because ' the DropDownList control is recreated each time the pager ' row gets created, this will persist the selected item in ' the DropDownList control. If i = CustomersGridView.PageIndex Then item.Selected = True End If ' Add the ListItem object to the Items collection of the ' DropDownList. pageList.Items.Add(item) Next i End If If Not pageLabel Is Nothing Then ' Calculate the current page number. Dim currentPage As Integer = CustomersGridView.PageIndex + 1 ' Update the Label control with the current page information. pageLabel.Text = "Page " & currentPage.ToString() & _ " of " & CustomersGridView.PageCount.ToString() End If End Sub </script> <html> <body> <form runat="server"> <h3>GridView PagerTemplate Example</h3> <asp:gridview id="CustomersGridView" datasourceid="CustomersSqlDataSource" autogeneratecolumns="true" allowpaging="true" ondatabound="CustomersGridView_DataBound" runat="server"> <pagerstyle forecolor="Blue" backcolor="LightBlue"/> <pagertemplate> <table width="100%"> <tr> <td width="70%"> <asp:label id="MessageLabel" forecolor="Blue" text="Select a page:" runat="server"/> <asp:dropdownlist id="PageDropDownList" autopostback="true" onselectedindexchanged="PageDropDownList_SelectedIndexChanged" runat="server"/> </td> <td width="70%" align="right"> <asp:label id="CurrentPageLabel" forecolor="Blue" runat="server"/> </td> </tr> </table> </pagertemplate> </asp:gridview> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Northwind sample database. Use an ASP.NET --> <!-- expression to retrieve the connection string value --> <!-- from the Web.config file. --> <asp:sqldatasource id="CustomersSqlDataSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"> </asp:sqldatasource> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> void PageDropDownList_SelectedIndexChanged(Object sender, EventArgs e) { // Retrieve the pager row. GridViewRow pagerRow = CustomersGridView.BottomPagerRow; // Retrieve the PageDropDownList DropDownList from the bottom pager row. DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList"); // Set the PageIndex property to display that page selected by the user. CustomersGridView.PageIndex = pageList.SelectedIndex; } void CustomersGridView_DataBound(Object sender, EventArgs e) { // Retrieve the pager row. GridViewRow pagerRow = CustomersGridView.BottomPagerRow; // Retrieve the DropDownList and Label controls from the row. DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList"); Label pageLabel = (Label)pagerRow.Cells[0].FindControl("CurrentPageLabel"); if(pageList != null) { // Create the values for the DropDownList control based on // the total number of pages required to display the data // source. for(int i=0; i<CustomersGridView.PageCount; i++) { // Create a ListItem object to represent a page. int pageNumber = i + 1; ListItem item = new ListItem(pageNumber.ToString()); // If the ListItem object matches the currently selected // page, flag the ListItem object as being selected. Because // the DropDownList control is recreated each time the pager // row gets created, this will persist the selected item in // the DropDownList control. if(i==CustomersGridView.PageIndex) { item.Selected = true; } // Add the ListItem object to the Items collection of the // DropDownList. pageList.Items.Add(item); } } if(pageLabel != null) { // Calculate the current page number. int currentPage = CustomersGridView.PageIndex + 1; // Update the Label control with the current page information. pageLabel.Text = "Page " + currentPage.ToString() + " of " + CustomersGridView.PageCount.ToString(); } } </script> <html> <body> <form runat="server"> <h3>GridView PagerTemplate Example</h3> <asp:gridview id="CustomersGridView" datasourceid="CustomersSqlDataSource" autogeneratecolumns="true" allowpaging="true" ondatabound="CustomersGridView_DataBound" runat="server"> <pagerstyle forecolor="Blue" backcolor="LightBlue"/> <pagertemplate> <table width="100%"> <tr> <td width="70%"> <asp:label id="MessageLabel" forecolor="Blue" text="Select a page:" runat="server"/> <asp:dropdownlist id="PageDropDownList" autopostback="true" onselectedindexchanged="PageDropDownList_SelectedIndexChanged" runat="server"/> </td> <td width="70%" align="right"> <asp:label id="CurrentPageLabel" forecolor="Blue" runat="server"/> </td> </tr> </table> </pagertemplate> </asp:gridview> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Northwind sample database. Use an ASP.NET --> <!-- expression to retrieve the connection string value --> <!-- from the Web.config file. --> <asp:sqldatasource id="CustomersSqlDataSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"> </asp:sqldatasource> </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に収録されているすべての辞書からGridView.PagerTemplate プロパティを検索する場合は、下記のリンクをクリックしてください。

- GridView.PagerTemplate プロパティのページへのリンク