DynamicQueryStringParameter Class
Collapse the table of content
Expand the table of content

DynamicQueryStringParameter Class

 

Automatically generates a collection of parameters that is used to create the Where clause for the data source control by retrieving query string values.

Namespace:   System.Web.DynamicData
Assembly:  System.Web.DynamicData (in System.Web.DynamicData.dll)

System.Object
  System.Web.UI.WebControls.Parameter
    System.Web.DynamicData.DynamicQueryStringParameter

public class DynamicQueryStringParameter : Parameter, IWhereParametersProvider

NameDescription
System_CAPS_pubmethodDynamicQueryStringParameter()

Initializes a new instance of the DynamicQueryStringParameter class.

NameDescription
System_CAPS_pubpropertyConvertEmptyStringToNull

Gets or sets a value indicating whether the value that the Parameter object is bound to should be converted to null if it is String.Empty.(Inherited from Parameter.)

System_CAPS_pubpropertyDbType

Gets or sets the database type of the parameter.(Inherited from Parameter.)

System_CAPS_pubpropertyDefaultValue

Specifies a default value for the parameter, should the value that the parameter is bound to be uninitialized when the Evaluate method is called.(Inherited from Parameter.)

System_CAPS_pubpropertyDirection

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.)

System_CAPS_protpropertyIsTrackingViewState

Gets a value indicating whether the Parameter object is saving changes to its view state.(Inherited from Parameter.)

System_CAPS_pubpropertyName

Gets or sets the name of the parameter.(Inherited from Parameter.)

System_CAPS_pubpropertySize

Gets or sets the size of the parameter.(Inherited from Parameter.)

System_CAPS_pubpropertyType

Gets or sets the type of the parameter.(Inherited from Parameter.)

System_CAPS_protpropertyViewState

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.)

NameDescription
System_CAPS_protmethodClone()

Returns a duplicate of the current Parameter instance.(Inherited from Parameter.)

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodEvaluate(HttpContext, Control)

Throws an InvalidOperationException exception in all cases.(Overrides Parameter.Evaluate(HttpContext, Control).)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetDatabaseType()

Gets the DbType value that is equivalent to the CLR type of the current Parameter instance.(Inherited from Parameter.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodGetWhereParameters(IDynamicDataSource)

Returns a collection of Parameter objects that are automatically generated for the columns of a table by retrieving query string values.

System_CAPS_protmethodLoadViewState(Object)

Restores the data source view's previously saved view state.(Inherited from Parameter.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethodOnParameterChanged()

Calls the OnParametersChanged method of the ParameterCollection collection that contains the Parameter object.(Inherited from Parameter.)

System_CAPS_protmethodSaveViewState()

Saves the changes to the Parameter object's view state since the time the page was posted back to the server.(Inherited from Parameter.)

System_CAPS_protmethodSetDirty()

Marks the Parameter object so its state will be recorded in view state.(Inherited from Parameter.)

System_CAPS_pubmethodToString()

Converts the value of this instance to its equivalent string representation.(Inherited from Parameter.)

System_CAPS_protmethodTrackViewState()

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.)

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodICloneable.Clone()

Returns a duplicate of the current Parameter instance.(Inherited from Parameter.)

System_CAPS_pubinterfaceSystem_CAPS_privmethodIStateManager.LoadViewState(Object)

This API supports the product infrastructure and is not intended to be used directly from your code. Restores the data source view's previously saved view state.(Inherited from Parameter.)

System_CAPS_pubinterfaceSystem_CAPS_privmethodIStateManager.SaveViewState()

This API supports the product infrastructure and is not intended to be used directly from your code. Saves the changes to the Parameter object's view state since the time the page was posted back to the server.(Inherited from Parameter.)

System_CAPS_pubinterfaceSystem_CAPS_privmethodIStateManager.TrackViewState()

This API supports the product infrastructure and is not intended to be used directly from your code. 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.)

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIStateManager.IsTrackingViewState

This API supports the product infrastructure and is not intended to be used directly from your code. Gets a value indicating whether the Parameter object is saving changes to its view state.(Inherited from Parameter.)

The DynamicQueryStringParameter class is used by pages that are using ASP.NET Dynamic Data features. The 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.

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. For foreign keys or Boolean columns, you must set the Name property to the name of the column you want to filter.

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.

The following example shows how to use the DynamicQueryStringParameter object as filter when displaying data in a GridView control. The 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>

.NET Framework
Available since 3.5

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show:
© 2016 Microsoft