Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
DataPager Class
 QueryStringField Property

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
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)
Visual Basic (Declaration)
Public Property QueryStringField As String
Visual Basic (Usage)
Dim instance As DataPager
Dim value As String

value = instance.QueryStringField

instance.QueryStringField = value
C#
public string QueryStringField { get; set; }
Visual C++
public:
property String^ QueryStringField {
    String^ get ();
    void set (String^ value);
}
JScript
public function get QueryStringField () : String
public function set QueryStringField (value : String)
ASP.NET
<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 nullNothingnullptra null reference (Nothing in Visual Basic), 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 nullNothingnullptra null reference (Nothing in Visual Basic), 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.

Visual Basic
<%@ Page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html  >
  <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>

C#
<%@ Page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html  >
  <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>

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker