Export (0) Print
Expand All

QueryStringParameter.QueryStringField Property

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)

'Declaration
Public Property QueryStringField As String

Property Value

Type: System.String
The name of the query-string field that the parameter binds to.

The QueryStringField property identifies a name/value pair that is passed with the query string. The QueryStringField property identifies the name of the pair, whereas the QueryStringParameter property binds to its corresponding value at run time. If the expected query-string name/value pair is not passed to the page with the query string, the Evaluate method then tries to bind the parameter to the value of the DefaultValue property. If the DefaultValue property is not set, the Evaluate method fails to bind the parameter to a value.

The following example shows how to use a QueryStringParameter object together 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 property is provided in case the name/value pair is not passed with 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>

The following example shows how to use a QueryStringParameter object together with a SqlDataSource control to display data in a GridView control. The QueryStringParameter object is added to the SelectParameters collection, together with other parameter objects that are used for the output parameter and return value. To retrieve data, handle the values that are returned from the stored procedure. This code example is part of a larger example that is 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>

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft