TemplatePagerField クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
カスタム ページング UI を作成できるようにする DataPager フィールドを表します。
public ref class TemplatePagerField : System::Web::UI::WebControls::DataPagerField
public class TemplatePagerField : System.Web.UI.WebControls.DataPagerField
type TemplatePagerField = class
inherit DataPagerField
Public Class TemplatePagerField
Inherits DataPagerField
- 継承
例
次の例は、コントロールにフィールドを追加する TemplatePagerField 方法を DataPager 示しています。 この例では、 を TemplatePagerField 使用して、現在のページ番号、ページの合計数、およびレコードの合計数を表示します。 DataPagerコントロールには、2 つのNextPreviousPagerFieldフィールドと、ユーザーがデータをNumericPagerFieldページングできるようにするナビゲーション コントロールを表示するフィールドも含まれています。
<%@ Page language="C#" %>
<!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" >
<head id="Head1" runat="server">
<title>TemplatePagerField Example</title>
<style type="text/css">
body
{
text-align: center;
font: 12px Arial, Helvetica, sans-serif;
}
.item
{
border: solid 1px #458b74;
background: #e0ffff;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<h3>TemplatePagerField Example</h3>
<asp:ListView ID="ContactsListView"
DataSourceID="ContactsDataSource"
runat="server">
<LayoutTemplate>
<table runat="server" id="tblContacts" width="350">
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr runat="server">
<td class="item">
<asp:Label ID="IDLabel" runat="server" Text='<%#Eval("ContactID") %>' />
</td>
<td align="left" class="item">
<asp:Label ID="NameLabel" runat="server"
Text='<%#Eval("LastName") + ", " + Eval("FirstName")%>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<br />
<asp:DataPager runat="server"
ID="ContactsDataPager"
PageSize="20"
PagedControlID="ContactsListView">
<Fields>
<asp:TemplatePagerField>
<PagerTemplate>
<b>
Page
<asp:Label runat="server" ID="CurrentPageLabel"
Text="<%# Container.TotalRowCount>0 ? (Container.StartRowIndex / Container.PageSize) + 1 : 0 %>" />
of
<asp:Label runat="server" ID="TotalPagesLabel"
Text="<%# Math.Ceiling ((double)Container.TotalRowCount / Container.PageSize) %>" />
(
<asp:Label runat="server" ID="TotalItemsLabel"
Text="<%# Container.TotalRowCount%>" />
records)
<br />
</b>
</PagerTemplate>
</asp:TemplatePagerField>
<asp:NextPreviousPagerField
ButtonType="Button"
ShowFirstPageButton="true"
ShowNextPageButton="false"
ShowPreviousPageButton="false" />
<asp:NumericPagerField
PreviousPageText="< Prev 10"
NextPageText="Next 10 >"
ButtonCount="10" />
<asp:NextPreviousPagerField
ButtonType="Button"
ShowLastPageButton="true"
ShowNextPageButton="false"
ShowPreviousPageButton="false" />
</Fields>
</asp:DataPager>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the AdventureWorks sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:SqlDataSource ID="ContactsDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
SelectCommand="SELECT [ContactID], [FirstName], [LastName]
FROM Person.Contact">
</asp:SqlDataSource>
</form>
</body>
</html>
<%@ Page language="VB" %>
<!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" >
<head id="Head1" runat="server">
<title>TemplatePagerField Example</title>
<style type="text/css">
body
{
text-align: center;
font: 12px Arial, Helvetica, sans-serif;
}
.item
{
border: solid 1px #458b74;
background: #e0ffff;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<h3>TemplatePagerField Example</h3>
<asp:ListView ID="ContactsListView"
DataSourceID="ContactsDataSource"
runat="server">
<LayoutTemplate>
<table runat="server" id="tblContacts" width="350">
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr runat="server">
<td class="item">
<asp:Label ID="IDLabel" runat="server" Text='<%#Eval("ContactID") %>' />
</td>
<td align="left" class="item">
<asp:Label ID="NameLabel" runat="server"
Text='<%#Eval("LastName") & ", " & Eval("FirstName")%>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<br />
<asp:DataPager runat="server"
ID="ContactsDataPager"
PageSize="20"
PagedControlID="ContactsListView">
<Fields>
<asp:TemplatePagerField>
<PagerTemplate>
<b>
Page
<asp:Label runat="server" ID="CurrentPageLabel"
Text="<%# IIf(Container.TotalRowCount>0, (Container.StartRowIndex / Container.PageSize) + 1 , 0) %>" />
of
<asp:Label runat="server" ID="TotalPagesLabel"
Text="<%# Math.Ceiling (System.Convert.ToDouble(Container.TotalRowCount) / Container.PageSize) %>" />
(
<asp:Label runat="server" ID="TotalItemsLabel"
Text="<%# Container.TotalRowCount%>" />
records)
<br />
</b>
</PagerTemplate>
</asp:TemplatePagerField>
<asp:NextPreviousPagerField
ButtonType="Button"
ShowFirstPageButton="true"
ShowNextPageButton="false"
ShowPreviousPageButton="false" />
<asp:NumericPagerField
PreviousPageText="< Prev 10"
NextPageText="Next 10 >"
ButtonCount="10" />
<asp:NextPreviousPagerField
ButtonType="Button"
ShowLastPageButton="true"
ShowNextPageButton="false"
ShowPreviousPageButton="false" />
</Fields>
</asp:DataPager>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the AdventureWorks sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:SqlDataSource ID="ContactsDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
SelectCommand="SELECT [ContactID], [FirstName], [LastName]
FROM Person.Contact">
</asp:SqlDataSource>
</form>
</body>
</html>
次の例は、 イベントを PagerCommand 使用して、フィールド内でクリックされたボタンに応じて異なるアクションを実行する方法を TemplatePagerField 示しています。 この例では、 を TemplatePagerField 使用して、ユーザーがデータをページングできるようにするナビゲーション コントロールを表示します。
<%@ Page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
// <Snippet2>
protected void TemplatePagerField_OnPagerCommand(object sender, DataPagerCommandEventArgs e)
{
// Check which button raised the event
switch(e.CommandName)
{
case "Next":
int newIndex = e.Item.Pager.StartRowIndex + e.Item.Pager.PageSize;
if (newIndex <= e.TotalRowCount)
{
e.NewStartRowIndex = newIndex;
e.NewMaximumRows = e.Item.Pager.MaximumRows;
}
break;
case "Previous":
e.NewStartRowIndex = e.Item.Pager.StartRowIndex - e.Item.Pager.PageSize;
e.NewMaximumRows = e.Item.Pager.MaximumRows;
break;
case "First":
e.NewStartRowIndex = 0;
e.NewMaximumRows = e.Item.Pager.MaximumRows;
break;
}
}
// </Snippet2>
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>TemplatePagerField.OnPagerCommand Example</title>
<style type="text/css">
body
{
text-align: center;
font: 12px Arial, Helvetica, sans-serif;
}
.item
{
border: solid 1px #2F4F4F;
background: #E6E6FA;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<h3>TemplatePagerField.OnPagerCommand Example</h3>
<asp:ListView ID="StoresListView"
DataSourceID="StoresDataSource"
runat="server">
<LayoutTemplate>
<table width="350" runat="server" id="tblStore">
<tr runat="server">
<th runat="server">ID</th>
<th runat="server">Store Name</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr runat="server">
<td class="item">
<asp:Label ID="IDLabel" runat="server" Text='<%#Eval("CustomerID") %>' />
</td>
<td align="left" class="item">
<asp:Label ID="NameLabel" runat="server" Text='<%#Eval("Name")%>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<br />
<asp:DataPager runat="server"
ID="ContactsDataPager"
PageSize="30"
PagedControlID="StoresListView">
<Fields>
<asp:TemplatePagerField OnPagerCommand="TemplatePagerField_OnPagerCommand">
<PagerTemplate>
<asp:LinkButton ID="FirstButton" runat="server" CommandName="First"
Text="<<" Enabled='<%# Container.StartRowIndex > 0 %>' />
<asp:LinkButton ID="PreviousButton" runat="server" CommandName="Previous"
Text='<%# (Container.StartRowIndex - Container.PageSize + 1) + " - " + (Container.StartRowIndex) %>'
Visible='<%# Container.StartRowIndex > 0 %>' />
<asp:Label ID="CurrentPageLabel" runat="server"
Text='<%# (Container.StartRowIndex + 1) + "-" + (Container.StartRowIndex + Container.PageSize > Container.TotalRowCount ? Container.TotalRowCount : Container.StartRowIndex + Container.PageSize) %>' />
<asp:LinkButton ID="NextButton" runat="server" CommandName="Next"
Text='<%# (Container.StartRowIndex + Container.PageSize + 1) + " - " + (Container.StartRowIndex + Container.PageSize*2 > Container.TotalRowCount ? Container.TotalRowCount : Container.StartRowIndex + Container.PageSize*2) %>'
Visible='<%# (Container.StartRowIndex + Container.PageSize) < Container.TotalRowCount %>' />
</PagerTemplate>
</asp:TemplatePagerField>
</Fields>
</asp:DataPager>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the AdventureWorks sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:SqlDataSource ID="StoresDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
SelectCommand="SELECT [CustomerID], [Name] FROM Sales.Store ORDER BY [Name]">
</asp:SqlDataSource>
</form>
</body>
</html>
<%@ Page language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
' <Snippet2>
Protected Sub TemplatePagerField_OnPagerCommand(ByVal sender As Object, _
ByVal e As DataPagerCommandEventArgs)
' Check which button raised the event
Select Case e.CommandName
Case "Next"
Dim newIndex As Integer = e.Item.Pager.StartRowIndex + e.Item.Pager.PageSize
If newIndex <= e.TotalRowCount Then
e.NewStartRowIndex = newIndex
e.NewMaximumRows = e.Item.Pager.MaximumRows
End If
Case "Previous"
e.NewStartRowIndex = e.Item.Pager.StartRowIndex - e.Item.Pager.PageSize
e.NewMaximumRows = e.Item.Pager.MaximumRows
Case "First"
e.NewStartRowIndex = 0
e.NewMaximumRows = e.Item.Pager.MaximumRows
End Select
End Sub
' </Snippet2>
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>TemplatePagerField.OnPagerCommand Example</title>
<style type="text/css">
body
{
text-align: center;
font: 12px Arial, Helvetica, sans-serif;
}
.item
{
border: solid 1px #2F4F4F;
background: #E6E6FA;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<h3>TemplatePagerField.OnPagerCommand Example</h3>
<asp:ListView ID="StoresListView"
DataSourceID="StoresDataSource"
runat="server">
<LayoutTemplate>
<table width="350" runat="server" id="tblStore">
<tr runat="server">
<th runat="server">ID</th>
<th runat="server">Store Name</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr runat="server">
<td class="item">
<asp:Label ID="IDLabel" runat="server" Text='<%#Eval("CustomerID") %>' />
</td>
<td align="left" class="item">
<asp:Label ID="NameLabel" runat="server" Text='<%#Eval("Name")%>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<br />
<asp:DataPager runat="server"
ID="ContactsDataPager"
PageSize="30"
PagedControlID="StoresListView">
<Fields>
<asp:TemplatePagerField OnPagerCommand="TemplatePagerField_OnPagerCommand">
<PagerTemplate>
<asp:LinkButton ID="FirstButton" runat="server" CommandName="First"
Text="<<" Enabled='<%# Container.StartRowIndex > 0 %>' />
<asp:LinkButton ID="PreviousButton" runat="server" CommandName="Previous"
Text='<%# (Container.StartRowIndex - Container.PageSize + 1) & " - " & (Container.StartRowIndex) %>'
Visible='<%# Container.StartRowIndex > 0 %>' />
<asp:Label ID="CurrentPageLabel" runat="server"
Text='<%# (Container.StartRowIndex + 1) & "-" & (IIf(Container.StartRowIndex + Container.PageSize > Container.TotalRowCount, Container.TotalRowCount, Container.StartRowIndex + Container.PageSize)) %>' />
<asp:LinkButton ID="NextButton" runat="server" CommandName="Next"
Text='<%# (Container.StartRowIndex + Container.PageSize + 1) & " - " & (IIf(Container.StartRowIndex + Container.PageSize*2 > Container.TotalRowCount, Container.TotalRowCount, Container.StartRowIndex + Container.PageSize*2)) %>'
Visible='<%# (Container.StartRowIndex + Container.PageSize) < Container.TotalRowCount %>' />
</PagerTemplate>
</asp:TemplatePagerField>
</Fields>
</asp:DataPager>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the AdventureWorks sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:SqlDataSource ID="StoresDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
SelectCommand="SELECT [CustomerID], [Name] FROM Sales.Store ORDER BY [Name]">
</asp:SqlDataSource>
</form>
</body>
</html>
注釈
オブジェクトを TemplatePagerField 使用して、ユーザーがインターフェイスを実装するコントロールによって表示されるデータをページングできるようにするナビゲーション コントロールを IPageableItemContainer 表示します。 (コントロールの例を示します ListView )。オブジェクトを TemplatePagerField 使用して、レコードの合計数や現在のページ番号など、基になるデータ ソースに関する情報を表示することもできます。
TemplatePagerFieldフィールドには組み込みのレイアウトがありません。 そのため、テンプレートでレイアウトを明示的に作成する PagerTemplate 必要があります。 カスケード スタイル シート (CSS) クラスまたはインライン スタイル要素を使用して、コンテンツの書式設定を行うことができます。
プロパティを DataPager 使用して、 オブジェクトを TemplatePagerField 含むコントロールを Container
参照できます。 これは、取得されたレコードの数、ページの合計数、および同様の情報を表示するバインディング式を作成する場合に便利です。 これらのバインド式では、 などのStartRowIndexMaximumRowsPageSizeコントロールのDataPagerプロパティをTotalRowCount使用できます。
フィールドには TemplatePagerField イベントが PagerCommand 用意されています。これは通常、テンプレート内のボタンがクリックされたときにタスクを PagerTemplate 実行するために使用されます。
コンストラクター
TemplatePagerField() |
TemplatePagerField クラスの新しいインスタンスを初期化します。 |
プロパティ
DataPager |
DataPagerField オブジェクトが関連付けられているデータ ページャーへの参照を取得します。 (継承元 DataPagerField) |
IsTrackingViewState |
DataPagerField オブジェクトでビューステートの変化を追跡しているかどうかを示す値を取得します。 (継承元 DataPagerField) |
PagerTemplate |
DataPager コントロールのページャー フィールドのカスタム コンテンツを取得または設定します。 |
QueryStringHandled |
クエリ文字列フィールドが評価されたかどうかを示す値を取得または設定します。 (継承元 DataPagerField) |
QueryStringValue |
要求の URL からクエリ文字列フィールドの値を取得します。 (継承元 DataPagerField) |
ViewState |
同一のページに対する複数の要求にわたって、DataPagerField オブジェクトのビューステートを保存し、復元できるようにする状態情報のディクショナリを取得します。 (継承元 DataPagerField) |
Visible |
データ ページャー フィールドを表示するかどうかを示す値を取得または設定します。 (継承元 DataPagerField) |
メソッド
CloneField() |
DataPagerField から派生した現在のオブジェクトのコピーを作成します。 (継承元 DataPagerField) |
CopyProperties(DataPagerField) |
TemplatePagerField オブジェクトの現在のプロパティを、指定された DataPagerField オブジェクトにコピーします。 |
CreateDataPagers(DataPagerFieldItem, Int32, Int32, Int32, Int32) |
ページャー フィールド オブジェクトのユーザー インターフェイス (UI) コントロールを作成し、指定のコンテナーに追加します。 |
CreateField() |
TemplatePagerField クラスの新しいインスタンスを作成して返します。 |
Equals(Object) |
指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。 (継承元 Object) |
GetHashCode() |
既定のハッシュ関数として機能します。 (継承元 Object) |
GetQueryStringNavigateUrl(Int32) |
指定のページ番号を持つクエリ文字列フィールドが含まれる URL を作成します。 (継承元 DataPagerField) |
GetType() |
現在のインスタンスの Type を取得します。 (継承元 Object) |
HandleEvent(CommandEventArgs) |
TemplatePagerField オブジェクトで発生するイベントを処理し、適切なアクションを実行します。 |
LoadViewState(Object) |
以前に保存したビューステート情報を復元します。 (継承元 DataPagerField) |
MemberwiseClone() |
現在の Object の簡易コピーを作成します。 (継承元 Object) |
OnFieldChanged() |
|
OnPagerCommand(DataPagerCommandEventArgs) |
PagerCommand イベントを発生させます。 |
SaveViewState() |
DataPagerField オブジェクトのビューステートに加えられた変更を保存します。 (継承元 DataPagerField) |
ToString() |
現在のオブジェクトを表す文字列を返します。 (継承元 Object) |
TrackViewState() |
DataPagerField オブジェクトがそのビューステートの変更を追跡するようにします。これにより、変更をコントロールの ViewState プロパティに格納し、同じページに対する複数の要求の間で保持できるようになります。 (継承元 DataPagerField) |
イベント
PagerCommand |
TemplatePagerField オブジェクト内のボタンがクリックされたときに発生します。 |
明示的なインターフェイスの実装
IStateManager.IsTrackingViewState |
DataPagerField オブジェクトでビューステートの変化を追跡しているかどうかを示す値を取得します。 (継承元 DataPagerField) |
IStateManager.LoadViewState(Object) |
以前に保存したビューステート情報を復元します。 (継承元 DataPagerField) |
IStateManager.SaveViewState() |
DataPagerField オブジェクトのビューステートに加えられた変更を保存します。 (継承元 DataPagerField) |
IStateManager.TrackViewState() |
DataPagerField オブジェクトがそのビューステートの変更を追跡するようにします。これにより、変更をコントロールの ViewState プロパティに格納し、同じページに対する複数の要求の間で保持できるようになります。 (継承元 DataPagerField) |
適用対象
こちらもご覧ください
.NET
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示