DataPager.PagedControlID 属性

定义

获取或设置一个控件的 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; }
[<System.Web.UI.Themeable(false)>]
[<System.Web.WebCategory("Paging")>]
member this.PagedControlID : string with get, set
Public Overridable Property PagedControlID As String

属性值

String

一个控件的 ID,该控件包含的数据将由 DataPager 控件进行分页。The ID of the control that contains the data that will be paged by the DataPager control. 默认值为空字符串,表示未设置此属性。The default is an empty string, which indicates that this property is not set.

属性
ThemeableAttribute WebCategoryAttribute

示例

下面的示例演示如何使用 PagedControlID 属性动态地将 ListView 控件与控件相关联 DataPagerThe following example shows how to use the PagedControlID property to dynamically associate a ListView control with a DataPager control. 此代码示例是为构造函数提供的更大示例的一部分 DataPagerThis 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 ,以便对控件的数据进行分页 ListViewThe 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>

注解

使用 PagedControlID 属性指定控件的,该 ID 控件包含控件将分页的数据 DataPagerUse the PagedControlID property to specify the ID of the control that contains the data that will be paged by the DataPager control. 指定的控件必须实现 IPageableItemContainer 接口,并且必须使用与控件相同的命名容器 DataPagerThe specified control must implement the IPageableItemContainer interface and must use the same naming container as the DataPager control. 控件是您可以指定的控件的一个示例 ListViewAn 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. 例如,在控件中 ListViewPagedControlID 如果将控件置于模板内,则不需要设置属性 DataPager ListView.LayoutTemplateFor 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.

此属性的值存储在视图状态中。The value of this property is stored in view state.

适用于

另请参阅