ObjectDataSourceView.SelectParameters 属性

定义

获取参数集合,该集合包含由 SelectMethod 方法使用的参数。Gets the parameters collection containing the parameters that are used by the SelectMethod method.

public:
 property System::Web::UI::WebControls::ParameterCollection ^ SelectParameters { System::Web::UI::WebControls::ParameterCollection ^ get(); };
public System.Web.UI.WebControls.ParameterCollection SelectParameters { get; }
member this.SelectParameters : System.Web.UI.WebControls.ParameterCollection
Public ReadOnly Property SelectParameters As ParameterCollection

属性值

ParameterCollection

一个 ParameterCollection,包含 SelectMethod 属性指定的方法所使用的参数。A ParameterCollection that contains the parameters used by the method specified by the SelectMethod property.

示例

下面的代码示例演示如何使用控件检索单个数据记录 ObjectDataSource ,然后在控件中显示数据记录 DetailsViewThe following code example demonstrates how to retrieve a single data record using an ObjectDataSource control, and then display the data record in a DetailsView control. ObjectDataSource通过调用类的方法来检索特定雇员记录 GetEmployee EmployeeLogicThe ObjectDataSource retrieves a specific employee record by calling the GetEmployee method of the EmployeeLogic class. GetEmployee方法需要雇员 ID 参数。The GetEmployee method requires an employee ID parameter. ObjectDataSource控件使用 QueryStringParameter 其集合中的对象 SelectParameters 将 ID 传递到 GetEmployee 方法。The ObjectDataSource control uses a QueryStringParameter object in its SelectParameters collection to pass an ID to the GetEmployee method.

若要查看 EmployeeLogic 类和方法的示例实现 GetEmployee ,请参见 ObjectDataSourceTo view the example implementation of the EmployeeLogic class and the GetEmployee method, see ObjectDataSource.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS" Assembly="Samples.AspNet.CS" %>
<%@ Page language="c#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>ObjectDataSource - C# Example</title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">

        <asp:detailsview
          id="DetailsView1"
          runat="server"
          datasourceid="ObjectDataSource1">
        </asp:detailsview>

<!-- Security Note: The ObjectDataSource 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:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetEmployee"
          typename="Samples.AspNet.CS.EmployeeLogic" >
          <selectparameters>
            <asp:querystringparameter name="EmployeeID" querystringfield="empid" defaultvalue="-1" />
          </selectparameters>
        </asp:objectdatasource>

    </form>
  </body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB" Assembly="Samples.AspNet.VB" %>
<%@ Page language="vb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>ObjectDataSource - VB Example</title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">

        <asp:detailsview
          id="DetailsView1"
          runat="server"
          datasourceid="ObjectDataSource1">
        </asp:detailsview>

<!-- Security Note: The ObjectDataSource 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:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetEmployee"
          typename="Samples.AspNet.VB.EmployeeLogic" >
          <selectparameters>
            <asp:querystringparameter name="EmployeeID" querystringfield="empid" defaultvalue="-1" />
          </selectparameters>
        </asp:objectdatasource>

    </form>
  </body>
</html>

注解

集合中包含的参数的名称和类型 SelectParameters 必须与属性签名所指定的方法中的参数的名称和类型相匹配 SelectMethodThe names and types of the parameters that are contained in the SelectParameters collection must match the names and types of the parameters that are in the method specified by the SelectMethod property signature. 在使用提供参数的数据绑定控件(如 GridView 和)时, DetailsView ObjectDataSource 控件自动将集合中显式指定的所有参数与数据绑定控件提供的参数合并。When working with data-bound controls that supply parameters, such as GridView and DetailsView, the ObjectDataSource control automatically merges any parameters that are explicitly specified in the collection with those parameters that are provided by the data-bound control. 有关详细信息,请参阅 ObjectDataSource.SelectMethodFor more information, see ObjectDataSource.SelectMethod.

适用于

另请参阅