DynamicQueryStringParameter DynamicQueryStringParameter DynamicQueryStringParameter DynamicQueryStringParameter Class

定義

透過擷取查詢字串值,自動產生用來對資料來源控制項建立 Where 子句的參數集合。Automatically generates a collection of parameters that is used to create the Where clause for the data source control by retrieving query string values.

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
繼承
DynamicQueryStringParameterDynamicQueryStringParameterDynamicQueryStringParameterDynamicQueryStringParameter
實作

範例

下列範例顯示如何在DynamicQueryStringParameter GridView控制項中顯示資料時, 使用物件做為篩選準則。The following example shows how to use the DynamicQueryStringParameter object as filter when displaying data in a GridView control. 控制項包含一個TemplateField物件, 它會建立連結, 以使用外鍵值來設定查詢字串值。 GridViewThe GridView control contains a TemplateField object that creates a link that sets the query string value by using the foreign key value.

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

備註

DynamicQueryStringParameter類別是由使用 ASP.NET 動態資料功能的頁面所使用。The DynamicQueryStringParameter class is used by pages that are using ASP.NET Dynamic Data features. 類別會藉由抓取查詢字串Parameter值, 為數據表的主鍵、外鍵和布林資料行產生物件的集合。 DynamicQueryStringParameterThe DynamicQueryStringParameter class will generate a collection of Parameter objects for the primary keys, foreign keys, and Boolean columns of a table by retrieving query string values.

對於主鍵, 您可以直接加入DynamicQueryStringParameter物件, 而不需提供任何其他參數。For primary keys, you can simply add a DynamicQueryStringParameter object without supplying any other parameters. 動態資料將會產生主要金鑰或金鑰的參數。Dynamic Data will generate the parameters for the primary key or keys. 對於外鍵或布林資料行, 您必須將Name屬性設定為您要篩選之資料行的名稱。For foreign keys or Boolean columns, you must set the Name property to the name of the column you want to filter.

若要使用DynamicQueryStringParameter類別, 您必須DynamicDataManager將控制項加入至頁面, 而且您必須使用DynamicDataManager.RegisterControl方法, 向DynamicDataManager控制項註冊資料繫結控制項。In order to use the DynamicQueryStringParameter class, you must add a DynamicDataManager control to the page and you must register the data-bound control with the DynamicDataManager control by using the DynamicDataManager.RegisterControl method.

請參閱這項功能的執行時間程式碼範例:執行See a run-time code example of this feature: Run.

建構函式

DynamicQueryStringParameter() DynamicQueryStringParameter() DynamicQueryStringParameter() DynamicQueryStringParameter()

初始化 DynamicQueryStringParameter 類別的新執行個體。Initializes a new instance of the DynamicQueryStringParameter class.

方法

Clone() Clone() Clone() Clone()

傳回目前 Parameter 執行個體的複製。Returns a duplicate of the current Parameter instance.

(Inherited from Parameter)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
Evaluate(HttpContext, Control) Evaluate(HttpContext, Control) Evaluate(HttpContext, Control) Evaluate(HttpContext, Control)

在所有情況下都擲回 InvalidOperationException 例外狀況。Throws an InvalidOperationException exception in all cases.

GetDatabaseType() GetDatabaseType() GetDatabaseType() GetDatabaseType()

取得 DbType 值,該值等於目前 Parameter 執行個體的 CLR 型別。Gets the DbType value that is equivalent to the CLR type of the current Parameter instance.

(Inherited from Parameter)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
GetWhereParameters(IDynamicDataSource) GetWhereParameters(IDynamicDataSource) GetWhereParameters(IDynamicDataSource) GetWhereParameters(IDynamicDataSource)

傳回透過擷取查詢字串值對資料表的資料行自動產生的 Parameter 物件集合。Returns a collection of Parameter objects that are automatically generated for the columns of a table by retrieving query string values.

LoadViewState(Object) LoadViewState(Object) LoadViewState(Object) LoadViewState(Object)

將資料來源檢視還原成之前所儲存的檢視狀態。Restores the data source view's previously saved view state.

(Inherited from Parameter)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
OnParameterChanged() OnParameterChanged() OnParameterChanged() OnParameterChanged()

呼叫 OnParametersChanged(EventArgs) 集合的 ParameterCollection 方法,該集合包含給定的 Parameter 物件。Calls the OnParametersChanged(EventArgs) method of the ParameterCollection collection that contains the Parameter object.

(Inherited from Parameter)
SaveViewState() SaveViewState() SaveViewState() SaveViewState()

儲存自頁面回傳至伺服器以來 Parameter 物件檢視狀態的變更。Saves the changes to the Parameter object's view state since the time the page was posted back to the server.

(Inherited from Parameter)
SetDirty() SetDirty() SetDirty() SetDirty()

標記 Parameter 物件,以便將其狀態記錄在檢視狀態中。Marks the Parameter object so its state will be recorded in view state.

(Inherited from Parameter)
ToString() ToString() ToString() ToString()

將這個執行個體的值轉換為它的相等字串表示。Converts the value of this instance to its equivalent string representation.

(Inherited from Parameter)
TrackViewState() TrackViewState() TrackViewState() TrackViewState()

會造成 Parameter 物件追蹤其檢視狀態變更,以將這些變更儲存在控制項的 ViewState 物件中,並持續存取相同頁面的其他要求。Causes the Parameter object to track changes to its view state so they can be stored in the control's ViewState object and persisted across requests for the same page.

(Inherited from Parameter)

屬性

ConvertEmptyStringToNull ConvertEmptyStringToNull ConvertEmptyStringToNull ConvertEmptyStringToNull

取得或設定值,該值指示是否應將 Parameter 物件繫結至的值轉換成 null (如果其為 Empty)。Gets or sets a value indicating whether the value that the Parameter object is bound to should be converted to null if it is Empty.

(Inherited from Parameter)
DbType DbType DbType DbType

取得或設定參數的資料庫型別。Gets or sets the database type of the parameter.

(Inherited from Parameter)
DefaultValue DefaultValue DefaultValue DefaultValue

指定參數的預設值,當呼叫 Evaluate(HttpContext, Control) 方法時,要繫結的值應是此參數未初始化的值。Specifies a default value for the parameter, should the value that the parameter is bound to be uninitialized when the Evaluate(HttpContext, Control) method is called.

(Inherited from Parameter)
Direction Direction Direction Direction

表示此 Parameter 物件是否用來將值繫結至控制項,或是這個控制項是否可用來變更該值。Indicates whether the Parameter object is used to bind a value to a control, or the control can be used to change the value.

(Inherited from Parameter)
IStateManager.IsTrackingViewState IStateManager.IsTrackingViewState IStateManager.IsTrackingViewState IStateManager.IsTrackingViewState

取得值,指出 Parameter 物件是否正在將變更儲存到它的檢視狀態。Gets a value indicating whether the Parameter object is saving changes to its view state.

(Inherited from Parameter)
IsTrackingViewState IsTrackingViewState IsTrackingViewState IsTrackingViewState

取得值,指出 Parameter 物件是否正在將變更儲存到它的檢視狀態。Gets a value indicating whether the Parameter object is saving changes to its view state.

(Inherited from Parameter)
Name Name Name Name

取得或設定參數的名稱。Gets or sets the name of the parameter.

(Inherited from Parameter)
Size Size Size Size

取得或設定參數的大小。Gets or sets the size of the parameter.

(Inherited from Parameter)
Type Type Type Type

取得或設定參數的型別。Gets or sets the type of the parameter.

(Inherited from Parameter)
ViewState ViewState ViewState ViewState

取得狀態資訊的字典,允許您在相同頁面的多個要求之間,儲存和還原 Parameter 物件的檢視狀態。Gets a dictionary of state information that allows you to save and restore the view state of a Parameter object across multiple requests for the same page.

(Inherited from Parameter)

明確介面實作

ICloneable.Clone() ICloneable.Clone() ICloneable.Clone() ICloneable.Clone()

傳回目前 Parameter 執行個體的複製。Returns a duplicate of the current Parameter instance.

(Inherited from Parameter)
IStateManager.LoadViewState(Object) IStateManager.LoadViewState(Object) IStateManager.LoadViewState(Object) IStateManager.LoadViewState(Object)

將資料來源檢視還原成之前所儲存的檢視狀態。Restores the data source view's previously saved view state.

(Inherited from Parameter)
IStateManager.SaveViewState() IStateManager.SaveViewState() IStateManager.SaveViewState() IStateManager.SaveViewState()

儲存自頁面回傳至伺服器以來 Parameter 物件檢視狀態的變更。Saves the changes to the Parameter object's view state since the time the page was posted back to the server.

(Inherited from Parameter)
IStateManager.TrackViewState() IStateManager.TrackViewState() IStateManager.TrackViewState() IStateManager.TrackViewState()

會造成 Parameter 物件追蹤其檢視狀態變更,以將這些變更儲存在控制項的 ViewState 物件中,並持續存取相同頁面的其他要求。Causes the Parameter object to track changes to its view state so they can be stored in the control's ViewState object and persisted across requests for the same page.

(Inherited from Parameter)

適用於

另請參閱