DataPager.PagedControlID Propriété

Définition

Obtient ou définit le ID du contrôle qui contient les données qui seront paginées par le contrôle DataPager.

public:
 virtual property System::String ^ PagedControlID { System::String ^ get(); void set(System::String ^ value); };
[System.Web.UI.Themeable(false)]
public virtual string PagedControlID { get; set; }
[<System.Web.UI.Themeable(false)>]
member this.PagedControlID : string with get, set
Public Overridable Property PagedControlID As String

Valeur de propriété

Le ID du contrôle qui contient les données qui seront paginées par le contrôle DataPager. La valeur par défaut est une chaîne vide, ce qui signifie que cette propriété n'est pas définie.

Attributs

Exemples

L’exemple suivant montre comment utiliser la PagedControlID propriété pour associer dynamiquement un ListView contrôle à un DataPager contrôle. Cet exemple de code fait partie d’un exemple plus grand fourni pour le DataPager constructeur.

protected void Page_Load(object sender, EventArgs e)
{

  // Create a new DataPager object.
  DataPager CountryDataPager = new DataPager();

  // Set the DataPager object's properties.
  CountryDataPager.PagedControlID = CountryListView.ID;
  CountryDataPager.PageSize = 15;
  CountryDataPager.Fields.Add(new NumericPagerField());

  // Add the DataPager object to the Controls collection
  // of the form.
  form1.Controls.Add(CountryDataPager);

  CountryListView.DataBind();
}
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
  
  ' Create a new DataPager object.
  Dim CountryDataPager As New DataPager()
      
  ' Set the DataPager object's properties.
  CountryDataPager.PagedControlID = CountryListView.ID
  CountryDataPager.PageSize = 15
  CountryDataPager.Fields.Add(New NumericPagerField())
      
  ' Add the DataPager object to the Controls collection
  ' of the form.
  form1.Controls.Add(CountryDataPager)

  CountryListView.DataBind()
  
End Sub

L’exemple suivant montre comment définir de manière déclarative la PagedControlID propriété dans un DataPager contrôle afin de paginer les données d’un ListView contrôle.

<%@ 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>DataPager PagedControlID Example</title>
</head>
<body>
    <form id="form1" runat="server">
      
      <h3>DataPager PagedControlID Example</h3>
      
      <asp:DataPager ID="DepartmentsPager" runat="server" 
        PagedControlID="DepartmentsListView">
        <Fields>
          <asp:NumericPagerField />
        </Fields>
      </asp:DataPager>
      
      <asp:ListView ID="DepartmentsListView" 
        DataSourceID="DepartmentsDataSource"
        runat="server">
        <LayoutTemplate>
          <table cellpadding="2" width="500px">
            <tr>
              <th>Department Name</th>
              <th>Group</th>
            </tr>
            <tr runat="server" id="itemPlaceholder"></tr>
          </table>
        </LayoutTemplate>
        <ItemTemplate>
          <tr runat="server">
            <td>
              <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
            </td>
            <td>
              <asp:Label ID="GroupNameLabel" runat="server" Text='<%# Eval("GroupName") %>' />
            </td>
          </tr>
        </ItemTemplate>
      </asp:ListView>

      <!-- 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="DepartmentsDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"            
        SelectCommand="SELECT Name, GroupName FROM HumanResources.Department" >
      </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>DataPager PagedControlID Example</title>
</head>
<body>
    <form id="form1" runat="server">
      
      <h3>DataPager PagedControlID Example</h3>
      
      <asp:DataPager ID="DepartmentsPager" runat="server" 
        PagedControlID="DepartmentsListView">
        <Fields>
          <asp:NumericPagerField />
        </Fields>
      </asp:DataPager>
      
      <asp:ListView ID="DepartmentsListView" 
        DataSourceID="DepartmentsDataSource"
        runat="server">
        <LayoutTemplate>
          <table cellpadding="2" width="500px">
            <tr>
              <th>Department Name</th>
              <th>Group</th>
            </tr>
            <tr runat="server" id="itemPlaceholder"></tr>
          </table>
        </LayoutTemplate>
        <ItemTemplate>
          <tr runat="server">
            <td>
              <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
            </td>
            <td>
              <asp:Label ID="GroupNameLabel" runat="server" Text='<%# Eval("GroupName") %>' />
            </td>
          </tr>
        </ItemTemplate>
      </asp:ListView>

      <!-- 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="DepartmentsDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"            
        SelectCommand="SELECT Name, GroupName FROM HumanResources.Department" >
      </asp:SqlDataSource>
    </form>
  </body>
</html>

Remarques

Utilisez la PagedControlID propriété pour spécifier le ID du contrôle qui contient les données qui seront paginées par le DataPager contrôle. Le contrôle spécifié doit implémenter l’interface IPageableItemContainer et doit utiliser le même conteneur d’affectation de noms que le DataPager contrôle. Le contrôle est ListView un exemple de contrôle que vous pouvez spécifier.

Si cette propriété est une chaîne vide ou null, le DataPager contrôle vérifie si son contrôle conteneur implémente l’interface IPageableItemContainer . Par exemple, dans le ListView contrôle, la PagedControlID propriété n’a pas besoin d’être définie si vous placez le DataPager contrôle dans le ListView.LayoutTemplate modèle. Cela est dû au fait que le DataPager contrôle peut trouver automatiquement le ListView contrôle en examinant l’arborescence du contrôle.

La valeur de cette propriété est stockée dans l’état d’affichage.

S’applique à

Voir aussi