Export (0) Print
Expand All

DataPager.QueryStringField Property

Gets or sets the name of the query string field.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

public string QueryStringField { get; set; }
<asp:DataPager QueryStringField="String" />

Property Value

Type: System.String
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.

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.

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"

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>DataPager Example</title>
    <style type="text/css">
        border-top:solid 1px #9dbbcc;
        border-bottom:solid 1px #9dbbcc;
    <form id="form1" runat="server">

      <h3>DataPager QueryStringField Example</h3>

      <asp:DataPager runat="server" ID="DataPager1"
          <asp:NumericPagerField />
      <br /><br />

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

      <!-- The second DataPager control. -->
      <asp:DataPager runat="server" ID="DataPager2"
          <asp:NumericPagerField />

      <!-- 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]">


.NET Framework

Supported in: 4, 3.5

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

© 2014 Microsoft