DataPager.PagedControlID 屬性

定義

取得或設定控制項的 ID,這個控制項包含 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

屬性值

控制項的 ID,這個控制項包含 DataPager 控制項要進行分頁的資料。 預設為空字串,表示未設定這個屬性 (Property)。

屬性

範例

下列範例示範如何使用 PagedControlID 屬性,以動態方式將控制項與 DataPager 控制項產生關聯 ListView 。 此程式碼範例是建構函式所提供較大範例的 DataPager 一部分。

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

下列範例示範如何在 控制項中 DataPager 以宣告方式設定 PagedControlID 屬性,以分頁控制項的資料 ListView

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

備註

PagedControlID使用 屬性來指定 ID 控制項的 ,其中包含控制項將分頁 DataPager 的資料。 指定的控制項必須實作 IPageableItemContainer 介面,而且必須使用與 控制項相同的命名容器 DataPager 。 您可以指定之控制項的範例是 ListView 控制項。

如果這個屬性是空字串或 null ,控制項會 DataPager 檢查其容器控制項是否實作 IPageableItemContainer 介面。 例如,在 控制項中 ListView ,如果您將控制項放在 DataPager 範本內 ListView.LayoutTemplatePagedControlID 則不需要設定 屬性。 這是因為 DataPager 控制項可以藉由檢查控制項樹狀結構來自動尋找 ListView 控制項。

此屬性的值會儲存在檢視狀態中。

適用於

另請參閱