Export (0) Print
Expand All

QueryStringParameter.QueryStringField Property

Note: This property is new in the .NET Framework version 2.0.

Gets or sets the name of the query string field that the parameter binds to.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public string QueryStringField { get; set; }
/** @property */
public String get_QueryStringField ()

/** @property */
public void set_QueryStringField (String value)

public function get QueryStringField () : String

public function set QueryStringField (value : String)

Property Value

A string that identifies the query string field that the parameter binds to.

The QueryStringField identifies a name/value pair that is passed on the query string. While the QueryStringField property identifies the name of the pair, the QueryStringParameter binds to its corresponding value at run time. If the expected query string name/value pair is not passed to the Web Form on the query string, the Evaluate method binds the parameter to the value of the DefaultValue property, if it is set. If the DefaultValue is not set, the Evaluate method fails to bind the parameter to a value.

The following code example demonstrates how to declaratively use a QueryStringParameter with a SqlDataSource control to display data in a ListBox control. The QueryStringField property is set to the name of the expected query string field and the parameter is added to the SelectParameters collection. A DefaultValue is provided in case the expected name/value pair is not passed on the query string.

      <asp:ListBox
        id ="ListBox1"
        runat="server"
        DataSourceID="SqlDataSource1"
        DataValueField="EmployeeID"
        DataTextField="LastName" />
    
<!-- Use a query string that includes empId=1 -->
    
<!-- Security Note: The SqlDataSource uses a QueryStringParameter,
     Security Note: which does not perform validation of input from the client.
     Security Note: To validate the value of the QueryStringParameter, handle the Selecting event. -->

      <asp:SqlDataSource
        id="SqlDataSource1"
        runat="server"
        ConnectionString="<%$ ConnectionStrings:MyNorthwind %>"
        SelectCommand="Select EmployeeID, LastName From Employees where EmployeeID = @empId">
        <SelectParameters>
          <asp:QueryStringParameter Name="empId" QueryStringField="empId" />
        </SelectParameters>
      </asp:SqlDataSource>

<asp:ListBox
  id ="ListBox1"
  runat="server"
  DataValueField="EmployeeID"
  DataTextField="LastName" />

<asp:SqlDataSource
  id="SqlDataSource1"
  runat="server"
  ConnectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;"
  SelectCommand="Select EmployeeID, LastName From Employees where EmployeeID = @empId">
  <SelectParameters>
    <asp:QueryStringParameter runat="server" Name="empId" QueryStringField="empId" />
  </SelectParameters>
</asp:SqlDataSource>

The following code example demonstrates how to declaratively use a QueryStringParameter with a SqlDataSource control to display data in a GridView control. The QueryStringParameter is added to the SelectParameters collection, along with other parameter objects that are used as an output parameter and return value parameter. Handle values returned from the stored procedure used to retrieve data. This code example is part of a larger example provided for the SqlDataSourceStatusEventArgs class.

<asp:sqldatasource
    id="SqlDataSource1"
    runat="server"
    datasourcemode="DataSet"
    connectionstring="<%$ ConnectionStrings:MyNorthwind%>"
    selectcommand="getordertotal"
    onselected="OnSelectedHandler">
    <selectparameters>
      <asp:querystringparameter name="empId" querystringfield="empId" />
      <asp:parameter name="total" type="Int32" direction="Output" defaultvalue="0" />
      <asp:parameter name="_ret" type="Int32" direction="ReturnValue" defaultvalue="0" />
    </selectparameters>
</asp:sqldatasource>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft