FormView.TopPagerRow プロパティ

定義

FormViewRow コントロールの上部に表示されるページ行を表す FormView オブジェクトを取得します。

public:
 virtual property System::Web::UI::WebControls::FormViewRow ^ TopPagerRow { System::Web::UI::WebControls::FormViewRow ^ get(); };
[System.ComponentModel.Browsable(false)]
public virtual System.Web.UI.WebControls.FormViewRow TopPagerRow { get; }
[<System.ComponentModel.Browsable(false)>]
member this.TopPagerRow : System.Web.UI.WebControls.FormViewRow
Public Overridable ReadOnly Property TopPagerRow As FormViewRow

プロパティ値

FormViewRow コントロールの上部のページ行を表す FormView

属性

次の例では、 プロパティを TopPagerRow 使用して、コントロールの上部に表示されるポケットベル行にアクセスする方法を FormView 示します。 その後、ページャー行が追加のコンテンツで更新されます。


<%@ 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">

  void EmployeeFormView_ItemCreated(Object sender, EventArgs e)
  {

    // Get the pager row.
    FormViewRow pagerRow = EmployeeFormView.TopPagerRow;

    // Get the Label controls that display the current page information 
    // from the pager row.
    Label pageNum = (Label)pagerRow.FindControl("PageNumberLabel");
    Label totalNum = (Label)pagerRow.FindControl("TotalPagesLabel");

    if ((pageNum != null) && (totalNum != null))
    {
      // Update the Label controls with the current page values.
      int page = EmployeeFormView.PageIndex + 1;
      int count = EmployeeFormView.PageCount;

      pageNum.Text = page.ToString();
      totalNum.Text = count.ToString();
    }

  }
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>FormView PagerTemplate Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>FormView PagerTemplate Example</h3>
                       
      <asp:formview id="EmployeeFormView"
        datasourceid="EmployeeSource"
        allowpaging="true"
        datakeynames="EmployeeID"
        onitemcreated="EmployeeFormView_ItemCreated" 
        runat="server">
        
        <itemtemplate>
          <table>
            <tr>
              <td>
                <asp:image id="EmployeeImage"
                  imageurl='<%# Eval("PhotoPath") %>'
                  alternatetext='<%# Eval("LastName") %>' 
                  runat="server"/>
              </td>
              <td>
                <h3><%# Eval("FirstName") %> <%# Eval("LastName") %></h3>      
                <%# Eval("Title") %>        
              </td>
            </tr>
          </table>    
        </itemtemplate>
        
        <pagertemplate>   
          <table width="100%">
            <tr>
              <td>
                <asp:linkbutton id="PreviousButton"
                  text="<"
                  commandname="Prev"
                  runat="Server"/>
                <asp:linkbutton id="NextButton"
                  text=">"
                  commandName="Next"
                  runat="Server"/> 
              </td>
              <td align="right">                
                Page <asp:label id="PageNumberLabel" runat="server"/> 
                of <asp:label id="TotalPagesLabel" runat="server"/>                
              </td>
            </tr>
          </table>          
        </pagertemplate>
          
        <pagersettings position="Top"
          mode="NextPrevious"/> 
                  
      </asp:formview>
          
      <!-- 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="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [PhotoPath] From [Employees]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
            
    </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">

  Sub EmployeeFormView_ItemCreated(ByVal sender As Object, ByVal e As EventArgs)

    ' Get the pager row.
    Dim pagerRow As FormViewRow = EmployeeFormView.TopPagerRow

    ' Get the Label controls that display the current page information 
    ' from the pager row.
    Dim pageNum As Label = CType(pagerRow.FindControl("PageNumberLabel"), Label)
    Dim totalNum As Label = CType(pagerRow.FindControl("TotalPagesLabel"), Label)

    If pageNum IsNot Nothing And totalNum IsNot Nothing Then

      ' Update the Label controls with the current page values.
      Dim page As Integer = EmployeeFormView.PageIndex + 1
      Dim count As Integer = EmployeeFormView.PageCount

      pageNum.Text = page.ToString()
      totalNum.Text = count.ToString()
    
    End If

  End Sub
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>FormView PagerTemplate Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>FormView PagerTemplate Example</h3>
                       
      <asp:formview id="EmployeeFormView"
        datasourceid="EmployeeSource"
        allowpaging="true"
        datakeynames="EmployeeID"
        onitemcreated="EmployeeFormView_ItemCreated" 
        runat="server">
        
        <itemtemplate>
          <table>
            <tr>
              <td>
                <asp:image id="EmployeeImage"
                  imageurl='<%# Eval("PhotoPath") %>'
                  alternatetext='<%# Eval("LastName") %>' 
                  runat="server"/>
              </td>
              <td>
                <h3><%# Eval("FirstName") %> <%# Eval("LastName") %></h3>      
                <%# Eval("Title") %>        
              </td>
            </tr>
          </table>    
        </itemtemplate>
        
        <pagertemplate>   
          <table width="100%">
            <tr>
              <td>
                <asp:linkbutton id="PreviousButton"
                  text="<"
                  commandname="Prev"
                  runat="Server"/>
                <asp:linkbutton id="NextButton"
                  text=">"
                  commandName="Next"
                  runat="Server"/> 
              </td>
              <td align="right">                
                Page <asp:label id="PageNumberLabel" runat="server"/> 
                of <asp:label id="TotalPagesLabel" runat="server"/>                
              </td>
            </tr>
          </table>          
        </pagertemplate>
          
        <pagersettings position="Top"
          mode="NextPrevious"/> 
                  
      </asp:formview>
          
      <!-- 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="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [PhotoPath] From [Employees]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
            
    </form>
  </body>
</html>

注釈

ページングが有効になっている場合 (プロパティが AllowPagingtrue設定されている場合)、ページャー行と呼ばれる追加の行がコントロールに FormView 自動的に表示されます。 ポケットベル行には、ユーザーが他のレコードに移動できるコントロールが含まれており、コントロールの上部、下部、または上部と下部の両方に表示できます。 プロパティを TopPagerRow 使用して、コントロールの FormViewRow トップ ページャー行を表す オブジェクトにプログラムで FormView アクセスします。

Note

プロパティは TopPagerRow 、コントロールがイベントで FormView トップ ページャー行を作成した ItemCreated 後にのみ使用できます。

このプロパティは、カスタム コンテンツを追加する場合など、トップ ページャー行をプログラムで操作する必要がある場合に一般的に使用されます。 プロパティの変更は、コントロールがデータに TopPagerRow バインドされた後 FormView に実行する必要があります。それ以外の FormView 場合、コントロールは変更を上書きします。

適用対象

こちらもご覧ください