DataPager.PagedControlID DataPager.PagedControlID DataPager.PagedControlID DataPager.PagedControlID Property

定義

取得或設定控制項的 ID,這個控制項包含 DataPager 控制項要進行分頁的資料。Gets or sets the ID of the control that contains the data that will be paged by the DataPager control.

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

屬性值

控制項的 ID,這個控制項包含 DataPager 控制項要進行分頁的資料。The ID of the control that contains the data that will be paged by the DataPager control. 預設為空字串,表示未設定這個屬性 (Property)。The default is an empty string, which indicates that this property is not set.

範例

下列範例顯示如何使用PagedControlID屬性, 以動態方式ListView將控制項與DataPager控制項產生關聯。The following example shows how to use the PagedControlID property to dynamically associate a ListView control with a DataPager control. 這個程式碼範例是針對此DataPager函式提供之較大範例的一部分。This code example is part of a larger example provided for the DataPager constructor.

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

下列範例顯示如何以宣告方式設定PagedControlID DataPager控制項中的屬性, 以ListView分頁控制項的資料。The following example shows how to declaratively set the PagedControlID property in a DataPager control in order to page the data of a ListView control.

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

備註

使用屬性, 即可指定控制項ID的, 其中包含DataPager控制項將會分頁的資料。 PagedControlIDUse the PagedControlID property to specify the ID of the control that contains the data that will be paged by the DataPager control. 指定的控制項必須執行IPageableItemContainer介面, 而且必須使用與DataPager控制項相同的命名容器。The specified control must implement the IPageableItemContainer interface and must use the same naming container as the DataPager control. 您可以指定的控制項範例是ListView控制項。An example of a control that you can specify is the ListView control.

如果這個屬性是空字串或null DataPager , 控制項會檢查IPageableItemContainer其容器控制項是否會執行介面。If this property is an empty string or null, the DataPager control checks whether its container control implements the IPageableItemContainer interface. 例如, 在ListView控制項中PagedControlID , 如果您ListView.LayoutTemplateDataPager控制項放在範本內, 則不需要設定屬性。For example, in the ListView control, the PagedControlID property does not have to be set if you put the DataPager control inside the ListView.LayoutTemplate template. 這是因為DataPager控制項可以藉由檢查控制項ListView樹狀結構來自動尋找控制項。This is because the DataPager control can automatically find the ListView control by examining the control tree.

這個屬性的值會儲存在 view 狀態中。The value of this property is stored in view state.

適用於

另請參閱