DataPager.QueryStringField Proprietà

Definizione

Ottiene o imposta il nome del campo della stringa di query.

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

Valore della proprietà

String

Nome del campo della stringa di query. L'impostazione predefinita è una stringa vuota che indica che il controllo DataPager utilizzerà un comando HTTP POST per spostarsi tra le pagine.

Attributi
WebCategoryAttribute

Esempio

Nell'esempio seguente viene illustrato come impostare in modo dichiarativo la QueryStringField proprietà in un DataPager controllo per spostarsi tra le pagine usando una stringa di query. Questo esempio contiene due DataPager controlli usati per la pagina tramite i dati visualizzati da un singolo ListView controllo.

<%@ 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>

Commenti

Utilizzare la QueryStringField proprietà per specificare che il DataPager controllo usa un comando HTTP GET per spostarsi tra le pagine. Nelle richieste GET viene aggiunto un campo stringa di query costituito da una coppia nome/valore all'URL della pagina. Il nome viene impostato utilizzando la QueryStringField proprietà . Il valore è il numero di pagina corrispondente. Se QueryStringField è una stringa vuota o null, il controllo usa un comando HTTP POST per spostarsi tra le pagine.

L'impostazione di questa proprietà è utile se si desidera che tutte le pagine di dati siano indicizzate da un motore di ricerca. Ciò si verifica perché il controllo produce un URL diverso per ogni pagina di dati.

Quando si imposta la QueryStringField proprietà, le condizioni seguenti potrebbero essere applicate:

  • È presente più DataPager di un controllo in una pagina e fanno riferimento allo stesso controllo associato a dati. In tal caso, assicurarsi che la QueryStringField proprietà di questi DataPager controlli sia impostata sullo stesso valore.

  • In una pagina sono presenti più DataPager controlli e fanno riferimento a controlli associati a dati diversi. In tal caso, assicurarsi che la QueryStringField proprietà di questi DataPager controlli sia impostata su valori diversi. Se si impostano i DataPager controlli sullo stesso valore, i controlli associati verranno impaginati contemporaneamente, perché useranno lo stesso campo stringa di query.

Se non si seguono le linee guida precedenti, può verificarsi un comportamento di paging imprevisto. Tuttavia, nessuna eccezione verrà generata dal controllo.

Se QueryStringField la proprietà non è una stringa vuota o null, il valore della ButtonType proprietà di NumericPagerField o NextPreviousPagerField oggetti viene ignorato. In tal caso, questi oggetti usano il controllo per creare i HyperLink pulsanti di spostamento.

Si applica a

Vedi anche