DataPager.QueryStringField DataPager.QueryStringField DataPager.QueryStringField DataPager.QueryStringField Property

定義

取得或設定查詢字串欄位的名稱。Gets or sets the name of the query string field.

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

屬性值

查詢字串欄位的名稱。The name of the query string field. 預設值是空字串,表示 DataPager 控制項會使用 HTTP POST 命令來巡覽頁面。The default is an empty string, which indicates that the DataPager control will use a HTTP POST command to navigate through the pages.

範例

下列範例顯示如何以宣告方式設定QueryStringField DataPager控制項中的屬性, 以便使用查詢字串流覽頁面。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. 這個範例包含兩DataPager個控制項, 可用來逐頁查看單一ListView控制項所顯示的資料。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>

備註

使用屬性, 即可指定DataPager控制項使用 HTTP GET 命令來流覽頁面。 QueryStringFieldUse the QueryStringField property to specify that the DataPager control uses an HTTP GET command to navigate through the pages. 在 GET 要求中, 包含名稱/值組的查詢字串欄位會加入至頁面的 URL 中。In GET requests, a query string field that consists of a name/value pair is added to the URL of the page. 此名稱是使用QueryStringField屬性來設定。The name is set by using the QueryStringField property. 值是對應的頁碼。The value is the corresponding page number. 如果QueryStringField是空字串或null, 控制項會使用 HTTP POST 命令來流覽頁面。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. 發生這種情況的原因是控制項會針對每一頁的資料產生不同的 URL。This occurs because the control produces a different URL for each page of data.

當您設定QueryStringField屬性時, 可能會適用下列條件:When you set the QueryStringField property, the following conditions might apply:

  • 您在頁面中有DataPager一個以上的控制項, 而且它們參考相同的資料繫結控制項。You have more than one DataPager control in a page and they reference the same data-bound control. 在這種情況下, 請確定QueryStringField這些DataPager控制項的屬性設定為相同的值。In that case, make sure that the QueryStringField property of these DataPager controls is set to the same value.

  • 您在頁面中有DataPager一個以上的控制項, 而且它們參考不同的資料繫結控制項。You have more than one DataPager control in a page and they reference different data-bound controls. 在這種情況下, 請確定QueryStringField這些DataPager控制項的屬性設定為不同的值。In that case, make sure that the QueryStringField property of these DataPager controls is set to different values. 如果您將DataPager控制項設為相同的值, 相關聯的資料繫結控制項就會同時分頁, 因為它們會使用相同的查詢字串欄位。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.

如果QueryStringField屬性不是空字串或ButtonType null, 則會忽略NumericPagerFieldNextPreviousPagerField物件的屬性值。If QueryStringField property is not an empty string or null, the value of the ButtonType property of NumericPagerField or NextPreviousPagerField objects is ignored. 在此情況下, 這些物件會HyperLink使用控制項來建立其瀏覽按鈕。In that case, these objects use the HyperLink control to create their navigation buttons.

適用於

另請參閱