Redigera

Dela via


QueryStringParameter.QueryStringField Property

Definition

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

public:
 property System::String ^ QueryStringField { System::String ^ get(); void set(System::String ^ value); };
public string QueryStringField { get; set; }
member this.QueryStringField : string with get, set
Public Property QueryStringField As String

Property Value

The name of the query-string field that the parameter binds to.

Examples

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

Remarks

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.

Applies to