DetailsView.TopPagerRow Propriété

Définition

Obtient un objet DetailsViewRow qui représente la ligne du haut du pagineur dans un contrôle DetailsView.

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

Valeur de propriété

DetailsViewRow qui représente la ligne du haut du pagineur dans le contrôle DetailsView.

Attributs

Exemples

L’exemple de code suivant montre comment utiliser la TopPagerRow propriété pour accéder à la ligne du pagineur supérieur du DetailsView contrôle pendant l’événement ItemCreated . Deux Label contrôles dans la ligne du pagineur personnalisé sont ensuite mis à jour avec le numéro de page actuel et le nombre total de pages.


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

    protected void CustomerDetailView_DataBound(object sender, EventArgs e)
    {

        // Get the pager row.
        DetailsViewRow pagerRow = CustomerDetailView.TopPagerRow;

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

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

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

    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

  <head runat="server">
    <title>DetailsView TopPagerRow Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView TopPagerRow Example</h3>
              
        <!-- Notice that the LinkButton controls in the pager   -->
        <!-- template have their CommandName properties set.    -->
        <!-- The DetailsView control automatically recognizes   -->
        <!-- certain command names and performs the appropriate -->
        <!-- operation. In this example, the CommandName        -->
        <!-- properties are set to "Next" and "Prev", which     -->
        <!-- causes the DetailsView control to navigate to the  -->
        <!-- next and previous record, respectively.            -->        
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          autogeneraterows="true" 
          allowpaging="true"
          runat="server" OnDataBound="CustomerDetailView_DataBound">
               
          <fieldheaderstyle backcolor="Navy"
            forecolor="White"/>
            
          <PagerSettings Position="top" /> 
          
          <pagertemplate>
            <table width="100%">
              <tr>
                <td>
                  <asp:LinkButton id="PreviousButton"
                    text="<"
                    CommandName="Page"
                    CommandArgument="Prev"
                    runat="Server"/>
                  <asp:LinkButton id="NextButton"
                    text=">"
                    CommandName="Page"
                    CommandArgument="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>   
                    
        </asp:detailsview>
        <!-- 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="DetailsViewSource" runat="server" 
          ConnectionString=
            "<%$ ConnectionStrings:NorthWindConnectionString%>"
            InsertCommand="INSERT INTO [Customers]([CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country]) VALUES (@CustomerID, @CompanyName, @Address, @City, @PostalCode, @Country)"
          SelectCommand="Select [CustomerID], [CompanyName], 
            [Address], [City], [PostalCode], [Country] From 
            [Customers]">
        </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">

    Protected Sub CustomerDetailView_DataBound(ByVal sender As Object, ByVal e As EventArgs)
        ' Get the pager row.
        Dim pagerRow As DetailsViewRow = CustomerDetailView.TopPagerRow

        ' Get the Label controls that display the current page information 
        ' from the pager row.
        Dim pageNum As Label = CType(pagerRow.Cells(0).FindControl("PageNumberLabel"), Label)
        Dim totalNum As Label = CType(pagerRow.Cells(0).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 = CustomerDetailView.DataItemIndex + 1
            Dim count As Integer = CustomerDetailView.DataItemCount

            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>DetailsView TopPagerRow Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView TopPagerRow Example</h3>
              
        <!-- Notice that the LinkButton controls in the pager   -->
        <!-- template have their CommandName properties set.    -->
        <!-- The DetailsView control automatically recognizes   -->
        <!-- certain command names and performs the appropriate -->
        <!-- operation. In this example, the CommandName        -->
        <!-- properties are set to "Page"                       -->
        <!-- and the CommandArgument                            -->
        <!-- properties are set to "Next" and "Prev", which     -->
        <!-- causes the DetailsView control to navigate to the  -->
        <!-- next and previous record, respectively.            -->        
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          autogeneraterows="true" 
          allowpaging="true"
          runat="server" 
          OnDataBound="CustomerDetailView_DataBound">
               
          <fieldheaderstyle backcolor="Navy"
            forecolor="White"/>
            
          <PagerSettings Position="top" /> 
          
          <pagertemplate>
            <table width="100%">
              <tr>
                <td>
                  <asp:LinkButton id="PreviousButton"
                    text="<"
                    CommandName="Page"
                    CommandArgument="Prev"
                    runat="Server"/>
                  <asp:LinkButton id="NextButton"
                    text=">"
                    CommandName="Page"
                    CommandArgument="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>   
                    
        </asp:detailsview>
        <!-- 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="DetailsViewSource" runat="server" 
          ConnectionString=
            "<%$ ConnectionStrings:NorthWindConnectionString%>"
            InsertCommand="INSERT INTO [Customers]([CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country]) VALUES (@CustomerID, @CompanyName, @Address, @City, @PostalCode, @Country)"
          SelectCommand="Select [CustomerID], [CompanyName], 
            [Address], [City], [PostalCode], [Country] From 
            [Customers]">
        </asp:SqlDataSource>
    </form>
  </body>
</html>

Remarques

Lorsque la pagination est activée (en définissant la AllowPaging propriété sur true), une ligne supplémentaire appelée ligne du pagineur s’affiche automatiquement dans le DetailsView contrôle. La ligne du pagineur contient des contrôles qui permettent à l’utilisateur de naviguer vers d’autres enregistrements et peuvent être affichés en haut, en bas ou en haut et en bas du contrôle. Utilisez la TopPagerRow propriété pour accéder par programmation à l’objet DetailsViewRow qui représente la ligne du pagineur supérieur dans le DetailsView contrôle.

Notes

La TopPagerRow propriété n’est disponible qu’une fois que le DetailsView contrôle a créé la ligne du pagineur inférieure dans l’événement ItemCreated .

Cette propriété est couramment utilisée lorsque vous devez manipuler par programmation la ligne du pagineur supérieure, par exemple lors de l’ajout de contenu personnalisé. Toute modification de la TopPagerRow propriété doit être effectuée après le rendu du DetailsView contrôle ; sinon, le DetailsView contrôle remplacera les modifications.

S’applique à

Voir aussi