Επεξεργασία

Κοινή χρήση μέσω


DataPager.QueryStringField Property

Definition

Gets or sets the name of the query string field.

public:
 property System::String ^ QueryStringField { System::String ^ get(); void set(System::String ^ value); };
public string QueryStringField { get; set; }
member this.QueryStringField : string with get, set
Public Property QueryStringField As String

Property Value

The name of the query string field. The default is an empty string, which indicates that the DataPager control will use a HTTP POST command to navigate through the pages.

Examples

The following example shows how to declaratively set the QueryStringField property in a DataPager control in order to navigate through the pages by using a query string. This example contains two DataPager controls that are used to page through the data that is displayed by a single 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 Example</title>
    <style type="text/css">
      th
      {
        background-color:#eef4fa;
        border-top:solid 1px #9dbbcc;
        border-bottom:solid 1px #9dbbcc;
      }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DataPager QueryStringField Example</h3>
      
      <asp:DataPager runat="server" ID="DataPager1"
        PagedControlID="CountriesListView" 
        QueryStringField="pageNumber">
        <Fields>
          <asp:NumericPagerField />
        </Fields>
      </asp:DataPager>
      <br /><br />

      <asp:ListView ID="CountriesListView" 
        DataSourceID="CountryDataSource"
        runat="server" >
        <LayoutTemplate>
          <table cellpadding="4" width="500" runat="server" id="tblCountries">
            <tr runat="server">
              <th runat="server">Code</th>
              <th runat="server">Name</th>
            </tr>
            <tr runat="server" id="itemPlaceholder" />
          </table>
        </LayoutTemplate>
        <ItemTemplate>
          <tr>
            <td>
              <asp:Label ID="CountryCodeLabel" runat="server" 
                Text='<%# Eval("CountryRegionCode")%>' />
            </td>          
            <td>
              <asp:Label ID="NameLabel" runat="server" 
                Text='<%# Eval("Name")%>' />
            </td>
          </tr>
        </ItemTemplate>
      </asp:ListView>
      <br />

      <!-- The second DataPager control. -->
      <asp:DataPager runat="server" ID="DataPager2"
        PagedControlID="CountriesListView" 
        QueryStringField="pageNumber">
        <Fields>
          <asp:NumericPagerField />
        </Fields>
      </asp:DataPager>

      <!-- 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="CountryDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
        SelectCommand="SELECT [CountryRegionCode], [Name]
          FROM [Person].[CountryRegion]">
      </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 Example</title>
    <style type="text/css">
      th
      {
        background-color:#eef4fa;
        border-top:solid 1px #9dbbcc;
        border-bottom:solid 1px #9dbbcc;
      }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DataPager QueryStringField Example</h3>
      
      <asp:DataPager runat="server" ID="DataPager1"
        PagedControlID="CountriesListView" 
        QueryStringField="pageNumber">
        <Fields>
          <asp:NumericPagerField />
        </Fields>
      </asp:DataPager>
      <br /><br />

      <asp:ListView ID="CountriesListView" 
        DataSourceID="CountryDataSource"
        runat="server" >
        <LayoutTemplate>
          <table cellpadding="4" width="500" runat="server" id="tblCountries">
            <tr runat="server">
              <th runat="server">Code</th>
              <th runat="server">Name</th>
            </tr>
            <tr runat="server" id="itemPlaceholder" />
          </table>
        </LayoutTemplate>
        <ItemTemplate>
          <tr>
            <td>
              <asp:Label ID="CountryCodeLabel" runat="server" 
                Text='<%# Eval("CountryRegionCode")%>' />
            </td>          
            <td>
              <asp:Label ID="NameLabel" runat="server" 
                Text='<%# Eval("Name")%>' />
            </td>
          </tr>
        </ItemTemplate>
      </asp:ListView>
      <br />

      <!-- The second DataPager control. -->
      <asp:DataPager runat="server" ID="DataPager2"
        PagedControlID="CountriesListView" 
        QueryStringField="pageNumber">
        <Fields>
          <asp:NumericPagerField />
        </Fields>
      </asp:DataPager>

      <!-- 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="CountryDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
        SelectCommand="SELECT [CountryRegionCode], [Name]
          FROM [Person].[CountryRegion]">
      </asp:SqlDataSource>
      
    </form>
  </body>
</html>

Remarks

Use the QueryStringField property to specify that the DataPager control uses an HTTP GET command to navigate through the pages. In GET requests, a query string field that consists of a name/value pair is added to the URL of the page. The name is set by using the QueryStringField property. The value is the corresponding page number. If QueryStringField is an empty string or null, the control uses an HTTP POST command to navigate through the pages.

Setting this property is useful if you want to have all the pages of data indexed by a search engine. This occurs because the control produces a different URL for each page of data.

When you set the QueryStringField property, the following conditions might apply:

  • You have more than one DataPager control in a page and they reference the same data-bound control. In that case, make sure that the QueryStringField property of these DataPager controls is set to the same value.

  • You have more than one DataPager control in a page and they reference different data-bound controls. In that case, make sure that the QueryStringField property of these DataPager controls is set to different values. If you set the DataPager controls to the same value, the associated data-bound controls will be paginated at the same time, because they will use the same query-string field.

If you do not follow the previous guidelines, unexpected paging behavior can occur. However, no exception will be thrown by the control.

If QueryStringField property is not an empty string or null, the value of the ButtonType property of NumericPagerField or NextPreviousPagerField objects is ignored. In that case, these objects use the HyperLink control to create their navigation buttons.

Applies to

See also