QueryStringParameter Constructors

Definition

Initializes a new instance of the QueryStringParameter class.

Overloads

QueryStringParameter()

Initializes a new unnamed instance of the QueryStringParameter class.

QueryStringParameter(QueryStringParameter)

Initializes a new instance of the QueryStringParameter class, using the values of the instance that is specified by the original parameter.

QueryStringParameter(String, String)

Initializes a new named instance of the QueryStringParameter class, using the specified string to identify which query-string field to bind to.

QueryStringParameter(String, DbType, String)

Initializes a new named instance of the QueryStringParameter class, using the specified query-string field and the data type of the parameter.

QueryStringParameter(String, TypeCode, String)

Initializes a new named and strongly typed instance of the QueryStringParameter class, using the specified string to identify which query-string field to bind to.

QueryStringParameter()

Initializes a new unnamed instance of the QueryStringParameter class.

public:
 QueryStringParameter();
public QueryStringParameter ();
Public Sub New ()

Examples

The following example shows how to use the QueryStringParameter constructor to create a new QueryStringParameter parameter and add it to the SelectParameters collection of an AccessDataSource control.

QueryStringParameter empIdParam = new QueryStringParameter();
empIdParam.Name = "empId";
empIdParam.QueryStringField = "empId";

AccessDataSource1.SelectParameters.Add(empIdParam);
Dim empIdParam As New QueryStringParameter()
empIdParam.Name = "empId"
empIdParam.QueryStringField = "empId"

AccessDataSource1.SelectParameters.Add(empIdParam)

The QueryStringParameter object is added to the AccessDataSource control and is declared in an ASP.NET Web page. The ListBox control uses the AccessDataSource control to bind and display data whenever the page is requested with a query string that contains a field that is named empId and that has a corresponding value.

<asp:ListBox
  id ="ListBox2"
  runat="server"
  DataSourceID="AccessDataSource1"
  DataValueField="EmployeeID"
  DataTextField="LastName" />

<asp:AccessDataSource
  id="AccessDataSource1"
  runat="server"
  DataFile="Northwind.mdb"
  SelectCommand="Select EmployeeID, LastName From Employees where EmployeeID = ?" />
<asp:ListBox
  id ="ListBox2"
  runat="server"
  DataSourceID="AccessDataSource1"
  DataValueField="EmployeeID"
  DataTextField="LastName" />

<asp:AccessDataSource
  id="AccessDataSource1"
  runat="server"
  DataFile="Northwind.mdb"
  SelectCommand="Select EmployeeID, LastName From Employees where EmployeeID = ?" />

Remarks

A QueryStringParameter object that is created by using the QueryStringParameter constructor is initialized with default values for all its properties. The properties are initialized as follows:

Applies to

QueryStringParameter(QueryStringParameter)

Initializes a new instance of the QueryStringParameter class, using the values of the instance that is specified by the original parameter.

protected:
 QueryStringParameter(System::Web::UI::WebControls::QueryStringParameter ^ original);
protected QueryStringParameter (System.Web.UI.WebControls.QueryStringParameter original);
new System.Web.UI.WebControls.QueryStringParameter : System.Web.UI.WebControls.QueryStringParameter -> System.Web.UI.WebControls.QueryStringParameter
Protected Sub New (original As QueryStringParameter)

Parameters

original
QueryStringParameter

A QueryStringParameter instance from which the current instance is initialized.

Remarks

The QueryStringParameter constructor is a protected copy constructor that is used to clone a QueryStringParameter instance. The values of the QueryStringField, Name, and Type properties are transferred to the new instance.

See also

Applies to

QueryStringParameter(String, String)

Initializes a new named instance of the QueryStringParameter class, using the specified string to identify which query-string field to bind to.

public:
 QueryStringParameter(System::String ^ name, System::String ^ queryStringField);
public QueryStringParameter (string name, string queryStringField);
new System.Web.UI.WebControls.QueryStringParameter : string * string -> System.Web.UI.WebControls.QueryStringParameter
Public Sub New (name As String, queryStringField As String)

Parameters

name
String

The name of the parameter.

queryStringField
String

The name of the query-string field that the parameter object is bound to. The default is an empty string ("").

Examples

The following example shows how to create two QueryStringParameter objects by using the QueryStringParameter constructor and add them to an AccessDataSource control's SelectParameters collection. A GridView control displays data if the employee and country query-string fields are passed with the request and if they have valid values.

<%@ 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">
private void Page_Load(object sender, System.EventArgs e)
{
    MyAccessDataSource.SelectParameters.Add(new QueryStringParameter("employee", "employee"));
    MyAccessDataSource.SelectParameters.Add(new QueryStringParameter("country",  "country"));
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="Form1" method="post" runat="server">

      <!-- Use a Query String that includes employee=1&country=USA -->
      <asp:gridview
        id ="GridView1"
        runat="server"
        datasourceid="MyAccessDataSource" />

<!-- Security Note: The AccessDataSource 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:accessdatasource
        id="MyAccessDataSource"
        runat="server"
        datafile="Northwind.mdb"
        selectcommand="SELECT EmployeeID, LastName, FirstName 
                       FROM Employees
                       WHERE EmployeeID = ? AND Country = ?">
      </asp:accessdatasource>

    </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">
Private Sub Page_Load(sender As Object, e As EventArgs)
    Dim param1 As New QueryStringParameter("employee", "employee")
    MyAccessDataSource.SelectParameters.Add(param1)

    Dim param2 As New QueryStringParameter("country", "country")
    MyAccessDataSource.SelectParameters.Add(param2)
End Sub ' Page_Load
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="Form1" method="post" runat="server">

      <!-- Use a Query String that includes employee=1&country=USA -->
      <asp:gridview
        id ="GridView1"
        runat="server"
        datasourceid="MyAccessDataSource" />

<!-- 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:accessdatasource
        id="MyAccessDataSource"
        runat="server"
        datafile="Northwind.mdb"
        selectcommand="SELECT EmployeeID, LastName, FirstName
                       FROM Employees
                       WHERE EmployeeID = ? AND Country = ? ">
      </asp:accessdatasource>
    </form>
  </body>
</html>

Remarks

A QueryStringParameter object that is created by using the QueryStringParameter constructor is initialized with the specified parameter name that identifies the query-string field that the parameter binds to. The Type and Direction properties are initialized with default values.

See also

Applies to

QueryStringParameter(String, DbType, String)

Initializes a new named instance of the QueryStringParameter class, using the specified query-string field and the data type of the parameter.

public:
 QueryStringParameter(System::String ^ name, System::Data::DbType dbType, System::String ^ queryStringField);
public QueryStringParameter (string name, System.Data.DbType dbType, string queryStringField);
new System.Web.UI.WebControls.QueryStringParameter : string * System.Data.DbType * string -> System.Web.UI.WebControls.QueryStringParameter
Public Sub New (name As String, dbType As DbType, queryStringField As String)

Parameters

name
String

The name of the parameter.

dbType
DbType

The data type of the parameter.

queryStringField
String

The name of the query-string field that the parameter object is bound to. The default is an empty string ("").

Applies to

QueryStringParameter(String, TypeCode, String)

Initializes a new named and strongly typed instance of the QueryStringParameter class, using the specified string to identify which query-string field to bind to.

public:
 QueryStringParameter(System::String ^ name, TypeCode type, System::String ^ queryStringField);
public QueryStringParameter (string name, TypeCode type, string queryStringField);
new System.Web.UI.WebControls.QueryStringParameter : string * TypeCode * string -> System.Web.UI.WebControls.QueryStringParameter
Public Sub New (name As String, type As TypeCode, queryStringField As String)

Parameters

name
String

The name of the parameter.

type
TypeCode

The type that the parameter represents. The default is Object.

queryStringField
String

The name of the query-string field that the parameter object is bound to. The default is an empty string ("").

Examples

The following example shows how to create a QueryStringParameter object by using the QueryStringParameter constructor and add it to an AccessDataSource control's FilterParameters collection. A GridView control displays data if the employee and country query-string fields are passed with the request and if they have valid values.

<%@ 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">
private void Page_Load(object sender, System.EventArgs e)
{
  QueryStringParameter countryFilter =
    new QueryStringParameter("country", TypeCode.String, "country");

  MyAccessDataSource.FilterParameters.Add(countryFilter);
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="Form1" method="post" runat="server">

      <!-- Use a Query String with country=USA -->
      <asp:gridview
        id ="GridView1"
        runat="server"
        datasourceid="MyAccessDataSource" />

<!-- Security Note: The AccessDataSource 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:accessdatasource
        id="MyAccessDataSource"
        runat="server"
        datafile="Northwind.mdb"
        selectcommand="SELECT EmployeeID, LastName, Address, PostalCode, Country FROM Employees"
        filterexpression="Country = '{0}'">
      </asp:accessdatasource>
    </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">
Private Sub Page_Load(sender As Object, e As EventArgs)
  Dim countryFilter As QueryStringParameter
  countryFilter = New QueryStringParameter("country", TypeCode.String, "country")
  MyAccessDataSource.FilterParameters.Add(countryFilter)
End Sub ' Page_Load
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="Form1" method="post" runat="server">

      <!-- Use a Query String with country=USA -->
      <asp:gridview
        id ="GridView1"
        runat="server"
        datasourceid="MyAccessDataSource" />

<!-- Security Note: The AccessDataSource 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:accessdatasource
        id="MyAccessDataSource"
        runat="server"
        datafile="Northwind.mdb"
        selectcommand="SELECT EmployeeID, LastName, Address, PostalCode, Country FROM Employees"
        filterexpression="Country = '{0}'">
      </asp:accessdatasource>
    </form>
  </body>
</html>

Remarks

A QueryStringParameter object that is created by using the QueryStringParameter constructor is initialized with the specified parameter name, the parameter type, and a string that identifies the query-string field that the parameter binds to. The Direction and ConvertEmptyStringToNull properties are initialized with default values.

See also

Applies to