QueryStringParameter 建構函式

定義

初始化 QueryStringParameter 類別的新執行個體。Initializes a new instance of the QueryStringParameter class.

多載

QueryStringParameter()

初始化 QueryStringParameter 類別未命名的新執行個體。Initializes a new unnamed instance of the QueryStringParameter class.

QueryStringParameter(QueryStringParameter)

初始化 QueryStringParameter 類別的新執行個體,使用由 original 參數指定的執行個體值。Initializes a new instance of the QueryStringParameter class, using the values of the instance that is specified by the original parameter.

QueryStringParameter(String, String)

使用指定的字串識別要繫結的查詢字串欄位,初始化 QueryStringParameter 類別的新具名執行個體。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)

使用指定的查詢字串欄位和參數的資料型別,初始化 QueryStringParameter 類別的新具名執行個體。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)

使用指定的字串識別要繫結的查詢字串欄位,初始化 QueryStringParameter 類別的新具名強型別 (Strongly Typed) 執行個體。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()

初始化 QueryStringParameter 類別未命名的新執行個體。Initializes a new unnamed instance of the QueryStringParameter class.

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

範例

下列範例顯示如何使用此函式 QueryStringParameter 來建立新的 QueryStringParameter 參數,並將其加入至 SelectParameters 控制項的集合 AccessDataSourceThe 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)

QueryStringParameter物件會加入至 AccessDataSource 控制項,並且在 ASP.NET 的網頁中宣告。The QueryStringParameter object is added to the AccessDataSource control and is declared in an ASP.NET Web page. ListBox AccessDataSource 當要求頁面的查詢字串中包含名為 empId 且具有對應值的欄位時,控制項會使用控制項來系結及顯示資料。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 = ?" />      

備註

QueryStringParameter使用此函式建立的物件會使用 QueryStringParameter 其所有屬性的預設值進行初始化。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:

適用於

QueryStringParameter(QueryStringParameter)

初始化 QueryStringParameter 類別的新執行個體,使用由 original 參數指定的執行個體值。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)

參數

original
QueryStringParameter

QueryStringParameter 執行個體,初始化目前執行個體的起源。A QueryStringParameter instance from which the current instance is initialized.

備註

此函式 QueryStringParameter 是用來複製實例的受保護複製函式 QueryStringParameterThe QueryStringParameter constructor is a protected copy constructor that is used to clone a QueryStringParameter instance. QueryStringField、和屬性的值 Name Type 會傳送至新的實例。The values of the QueryStringField, Name, and Type properties are transferred to the new instance.

另請參閱

適用於

QueryStringParameter(String, String)

使用指定的字串識別要繫結的查詢字串欄位,初始化 QueryStringParameter 類別的新具名執行個體。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)

參數

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

範例

下列範例示範如何使用函式來建立兩個 QueryStringParameter 物件 QueryStringParameter ,並將它們加入至 AccessDataSource 控制項的 SelectParameters 集合。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. GridView如果 employeecountry 查詢字串欄位與要求一起傳遞,且具有有效的值,控制項就會顯示資料。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>

備註

使用此函式所 QueryStringParameter 建立的物件 QueryStringParameter 會以指定的參數名稱初始化,以識別參數所系結的查詢字串欄位。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. TypeDirection 屬性會以預設值初始化。The Type and Direction properties are initialized with default values.

另請參閱

適用於

QueryStringParameter(String, DbType, String)

使用指定的查詢字串欄位和參數的資料型別,初始化 QueryStringParameter 類別的新具名執行個體。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)

參數

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

適用於

QueryStringParameter(String, TypeCode, String)

使用指定的字串識別要繫結的查詢字串欄位,初始化 QueryStringParameter 類別的新具名強型別 (Strongly Typed) 執行個體。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)

參數

name
String

參數名稱。The name of the parameter.

type
TypeCode

參數所代表的型別。The type that the parameter represents. 預設為 ObjectThe 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 ("").

範例

下列範例示範如何使用函式來建立 QueryStringParameter 物件 QueryStringParameter ,並將它加入至 AccessDataSource 控制項的 FilterParameters 集合。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. GridView如果 employeecountry 查詢字串欄位與要求一起傳遞,且具有有效的值,控制項就會顯示資料。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>

備註

QueryStringParameter使用此函式建立的物件 QueryStringParameter 會以指定的參數名稱、參數類型,以及識別參數所系結之查詢字串欄位的字串初始化。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. DirectionConvertEmptyStringToNull 屬性會以預設值初始化。The Direction and ConvertEmptyStringToNull properties are initialized with default values.

另請參閱

適用於