Condividi tramite


DynamicQueryStringParameter Classe

Definizione

Genera automaticamente una raccolta di parametri utilizzata per creare la Where clausola per il controllo origine dati recuperando i valori della stringa di query.

public ref class DynamicQueryStringParameter : System::Web::UI::WebControls::Parameter, System::Web::DynamicData::IWhereParametersProvider
public class DynamicQueryStringParameter : System.Web.UI.WebControls.Parameter, System.Web.DynamicData.IWhereParametersProvider
type DynamicQueryStringParameter = class
    inherit Parameter
    interface IWhereParametersProvider
Public Class DynamicQueryStringParameter
Inherits Parameter
Implements IWhereParametersProvider
Ereditarietà
DynamicQueryStringParameter
Implementazioni

Esempio

Nell'esempio seguente viene illustrato come usare l'oggetto DynamicQueryStringParameter come filtro durante la visualizzazione dei dati in un GridView controllo . Il GridView controllo contiene un TemplateField oggetto che crea un collegamento che imposta il valore della stringa di query utilizzando il valore della chiave esterna.

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

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

<script runat="server">
 
  protected void Page_Init(object sender, EventArgs e)
  {
    // Registers the data-bound control with
    // the DynamicDataManager control.
    DynamicDataManager1.RegisterControl(ProductsGridView);
    
    // Initializes the URL for the View All link 
    // to the current page.
    ViewAllLink.NavigateUrl = Request.Path;

  }

  protected string GetFilterPath()
  {
    // Retrieves the current data item.
    var productItem = (Product)GetDataItem();
    if (productItem.ProductCategory != null)
    {
      // Creates a URL that has a query string value
      // set to the foreign key value.      
      return Request.Path + "?ProductCategoryID=" 
        + productItem.ProductCategoryID.ToString();
    }
    return string.Empty;
  }

  protected string GetProductCategory()
  {
    // Returns the value for the Name column
    // in the relationship table.    
    var productItem = (Product)GetDataItem();
    if (productItem.ProductCategory != null)
    {
      return productItem.ProductCategory.Name;
    }
    return string.Empty;
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
  <title>DynamicQueryStringParameter Example</title>
  <link href="~/Site.css" rel="stylesheet" type="text/css" />
</head>
<body class="template">
  <form id="form1" runat="server">
    <div>
    
      <h2>DynamicQueryStringParameter Example</h2>
      
      <asp:DynamicDataManager ID="DynamicDataManager1" runat="server"
        AutoLoadForeignKeys="true" />
              
      <asp:GridView ID="ProductsGridView" runat="server"
        AutoGenerateColumns="false"
        DataSourceID="ProductsDataSource"
        AllowPaging="true"
        CssClass="gridview">
        <Columns>
          <asp:DynamicField DataField="Name" />
          <asp:DynamicField DataField="ProductNumber" />
          <asp:DynamicField DataField="Color" />
          <asp:TemplateField HeaderText="Category">
            <ItemTemplate>
              <a runat="server" href='<%# GetFilterPath() %>'>
                <asp:Label runat="server" ID="ProductCategory" Text='<%# GetProductCategory() %>' />
              </a>
            </ItemTemplate>
          </asp:TemplateField>
        </Columns>
      </asp:GridView>
      <br />
      
      <div class="bottomhyperlink">
        <asp:HyperLink runat="server" ID="ViewAllLink" Text="View All Records" />
      </div>


      <!-- This example uses Microsoft SQL Server and connects   -->
      <!-- to the AdventureWorksLT sample database.              -->
      <asp:LinqDataSource ID="ProductsDataSource" runat="server" 
        TableName="Products"
        ContextTypeName="AdventureWorksLTDataContext" >
        <WhereParameters>
          <asp:DynamicQueryStringParameter Name="ProductCategory" />
        </WhereParameters>
      </asp:LinqDataSource>
      
    </div>
  </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">

<script runat="server">
 
  Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs)
    ' Registers the data-bound control with
    ' the DynamicDataManager control.
    DynamicDataManager1.RegisterControl(ProductsGridView)
    
    ' Initializes the URL for the View All link 
    ' to the current page.
    ViewAllLink.NavigateUrl = Request.Path    
  End Sub

  Protected Function GetFilterPath() As String
    ' Retrieves the current data item.
    Dim productItem = CType(GetDataItem(), Product)
    If Not (productItem.ProductCategory Is Nothing) Then
      ' Creates a URL that has a query string value
      ' set to the foreign key value.
      Return Request.Path + "?ProductCategoryID=" + productItem.ProductCategoryID.ToString()
    End If
    Return String.Empty

  End Function

  Protected Function GetProductCategory() As String
    ' Returns the value for the Name column
    ' in the relationship table.
    Dim productItem = CType(GetDataItem(), Product)
    If Not (productItem.ProductCategory Is Nothing) Then
      Return productItem.ProductCategory.Name
    End If
    Return String.Empty
  End Function
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>DynamicQueryStringParameter Example</title>
  <link href="~/Site.css" rel="stylesheet" type="text/css" />
</head>
<body class="template">
  <form id="form1" runat="server">
    <div>
    
      <h2>DynamicQueryStringParameter Example</h2>
      
      <asp:DynamicDataManager ID="DynamicDataManager1" runat="server"
        AutoLoadForeignKeys="true" />
              
      <asp:GridView ID="ProductsGridView" runat="server"
        AutoGenerateColumns="false"
        DataSourceID="ProductsDataSource"
        AllowPaging="true"
        CssClass="gridview">
        <Columns>
          <asp:DynamicField DataField="Name" />
          <asp:DynamicField DataField="ProductNumber" />
          <asp:DynamicField DataField="Color" />
          <asp:TemplateField HeaderText="Category">
            <ItemTemplate>
              <a runat="server" href='<%# GetFilterPath() %>'>
                <asp:Label runat="server" ID="ProductCategory" Text='<%# GetProductCategory() %>' />
              </a>
            </ItemTemplate>
          </asp:TemplateField>
        </Columns>
      </asp:GridView>
      <br />
      
      <div class="bottomhyperlink">
        <asp:HyperLink runat="server" ID="ViewAllLink" Text="View All Records" />
      </div>


      <!-- This example uses Microsoft SQL Server and connects   -->
      <!-- to the AdventureWorksLT sample database.              -->
      <asp:LinqDataSource ID="ProductsDataSource" runat="server" 
        TableName="Products"
        ContextTypeName="AdventureWorksLTDataContext" >
        <WhereParameters>
          <asp:DynamicQueryStringParameter Name="ProductCategory" />
        </WhereParameters>
      </asp:LinqDataSource>
      
    </div>
  </form>
</body>
</html>

Commenti

La DynamicQueryStringParameter classe viene usata dalle pagine che usano ASP.NET funzionalità dynamic data. La DynamicQueryStringParameter classe genererà una raccolta di Parameter oggetti per le chiavi primarie, le chiavi esterne e le colonne booleane di una tabella recuperando i valori della stringa di query.

Per le chiavi primarie, è sufficiente aggiungere un DynamicQueryStringParameter oggetto senza fornire altri parametri. Dynamic Data genererà i parametri per la chiave o le chiavi primarie. Per le chiavi esterne o le colonne booleane, è necessario impostare la Name proprietà sul nome della colonna da filtrare.

Per usare la DynamicQueryStringParameter classe , è necessario aggiungere un DynamicDataManager controllo alla pagina ed è necessario registrare il controllo associato a dati con il DynamicDataManager controllo utilizzando il DynamicDataManager.RegisterControl metodo .

Costruttori

Nome Descrizione
DynamicQueryStringParameter()

Inizializza una nuova istanza della classe DynamicQueryStringParameter.

Proprietà

Nome Descrizione
ConvertEmptyStringToNull

Ottiene o imposta un valore che indica se il valore a cui è associato l'oggetto Parameter deve essere convertito null in se è Empty.

(Ereditato da Parameter)
DbType

Ottiene o imposta il tipo di database del parametro .

(Ereditato da Parameter)
DefaultValue

Specifica un valore predefinito per il parametro , se il valore associato al parametro deve essere non inizializzato quando viene chiamato il Evaluate(HttpContext, Control) metodo .

(Ereditato da Parameter)
Direction

Indica se l'oggetto Parameter viene utilizzato per associare un valore a un controllo o se il controllo può essere utilizzato per modificare il valore.

(Ereditato da Parameter)
IsTrackingViewState

Ottiene un valore che indica se l'oggetto Parameter sta salvando le modifiche apportate allo stato di visualizzazione.

(Ereditato da Parameter)
Name

Ottiene o imposta il nome del parametro.

(Ereditato da Parameter)
Size

Ottiene o imposta le dimensioni del parametro.

(Ereditato da Parameter)
Type

Ottiene o imposta il tipo del parametro.

(Ereditato da Parameter)
ViewState

Ottiene un dizionario di informazioni sullo stato che consente di salvare e ripristinare lo stato di visualizzazione di un Parameter oggetto in più richieste per la stessa pagina.

(Ereditato da Parameter)

Metodi

Nome Descrizione
Clone()

Restituisce un duplicato dell'istanza corrente Parameter .

(Ereditato da Parameter)
Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
Evaluate(HttpContext, Control)

Genera un'eccezione InvalidOperationException in tutti i casi.

GetDatabaseType()

Ottiene il DbType valore equivalente al tipo CLR dell'istanza corrente Parameter .

(Ereditato da Parameter)
GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetType()

Ottiene il Type dell'istanza corrente.

(Ereditato da Object)
GetWhereParameters(IDynamicDataSource)

Restituisce una raccolta di Parameter oggetti generati automaticamente per le colonne di una tabella recuperando i valori della stringa di query.

LoadViewState(Object)

Ripristina lo stato di visualizzazione salvata in precedenza della vista origine dati.

(Ereditato da Parameter)
MemberwiseClone()

Crea una copia superficiale del Objectcorrente.

(Ereditato da Object)
OnParameterChanged()

Chiama il OnParametersChanged(EventArgs) metodo dell'insieme ParameterCollection che contiene l'oggetto Parameter .

(Ereditato da Parameter)
SaveViewState()

Salva le modifiche apportate allo Parameter stato di visualizzazione dell'oggetto dal momento in cui la pagina è stata pubblicata nel server.

(Ereditato da Parameter)
SetDirty()

Contrassegna l'oggetto Parameter in modo che il relativo stato venga registrato nello stato di visualizzazione.

(Ereditato da Parameter)
ToString()

Converte il valore di questa istanza nella rappresentazione di stringa equivalente.

(Ereditato da Parameter)
TrackViewState()

Fa in modo che l'oggetto Parameter possa tenere traccia delle modifiche apportate allo stato di visualizzazione in modo che possano essere archiviate nell'oggetto del ViewState controllo e mantenute tra le richieste per la stessa pagina.

(Ereditato da Parameter)

Implementazioni dell'interfaccia esplicita

Nome Descrizione
ICloneable.Clone()

Restituisce un duplicato dell'istanza corrente Parameter .

(Ereditato da Parameter)
IStateManager.IsTrackingViewState

Ottiene un valore che indica se l'oggetto Parameter sta salvando le modifiche apportate allo stato di visualizzazione.

(Ereditato da Parameter)
IStateManager.LoadViewState(Object)

Ripristina lo stato di visualizzazione salvata in precedenza della vista origine dati.

(Ereditato da Parameter)
IStateManager.SaveViewState()

Salva le modifiche apportate allo Parameter stato di visualizzazione dell'oggetto dal momento in cui la pagina è stata pubblicata nel server.

(Ereditato da Parameter)
IStateManager.TrackViewState()

Fa in modo che l'oggetto Parameter possa tenere traccia delle modifiche apportate allo stato di visualizzazione in modo che possano essere archiviate nell'oggetto del ViewState controllo e mantenute tra le richieste per la stessa pagina.

(Ereditato da Parameter)

Si applica a

Vedi anche