DataPager.PagedControlID Właściwość

Definicja

Pobiera lub ustawia ID kontrolkę zawierającą dane, które będą stronicowane przez kontrolkę DataPager .

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

Wartość właściwości

String

Kontrolka ID zawierająca dane, które zostaną stronicowane przez kontrolkę DataPager . Wartość domyślna to pusty ciąg, który wskazuje, że ta właściwość nie jest ustawiona.

Atrybuty
ThemeableAttribute WebCategoryAttribute

Przykłady

W poniższym przykładzie pokazano, jak za pomocą PagedControlID właściwości dynamicznie skojarzyć kontrolkę ListView z kontrolką DataPager . Ten przykład kodu jest częścią większego przykładu podanego dla konstruktora 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

W poniższym przykładzie pokazano, jak deklaratywnie ustawić PagedControlID właściwość w kontrolce DataPager , aby stronicować dane kontrolki 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>

Uwagi

PagedControlID Użyj właściwości , aby określić ID kontrolkę zawierającą dane, które będą stronicowane przez kontrolkęDataPager. Określona kontrolka IPageableItemContainer musi zaimplementować interfejs i musi używać tego samego kontenera nazewnictwa co kontrolka DataPager . Przykładem kontrolki, którą można określić, jest kontrolka ListView .

Jeśli ta właściwość jest pustym ciągiem lub null, kontrolka DataPager sprawdza, czy jego kontrolka kontenera implementuje IPageableItemContainer interfejs. Na przykład w kontrolce ListView PagedControlID właściwość nie musi być ustawiana, jeśli umieścisz kontrolkę DataPager wewnątrz szablonu ListView.LayoutTemplate . Jest to spowodowane tym, że kontrolka DataPager może automatycznie znaleźć kontrolkę ListView , sprawdzając drzewo kontrolek.

Wartość tej właściwości jest przechowywana w stanie widoku.

Dotyczy

Zobacz też