ObjectDataSourceView.InsertParameters 속성

정의

InsertMethod 메서드에서 사용하는 매개 변수가 포함된 매개 변수 컬렉션을 가져옵니다.

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

속성 값

ParameterCollection

ParameterCollection 속성에서 사용하는 매개 변수가 포함된 InsertMethod입니다.

예제

이 섹션에는 두 코드 예제가 있습니다. 첫 번째 코드 예제에 사용 하 여 필터링 된 데이터를 표시 하는 방법을 보여 줍니다.는 ObjectDataSource 비즈니스 개체를 사용 하 여 컨트롤 및 DetailsView 데이터 삽입을 제어 합니다. 두 번째 코드 예의 예제 구현을 제공 합니다 Insert 첫 번째 코드 예제에 사용 되는 메서드.

다음 코드 예제에 사용 하는 방법을 보여 줍니다.는 ObjectDataSource 비즈니스 개체를 사용 하 여 컨트롤 및 DetailsView 데이터 삽입을 제어 합니다. 합니다 DetailsView 처음에 새 표시 NorthwindEmployee 함께 자동으로 생성 된 레코드 삽입 단추입니다. 데이터의 필드에 입력 한 후 합니다 DetailsView 컨트롤을 클릭 합니다 삽입 단추입니다. 합니다 InsertMethod 속성은 수행 하는 메서드를 식별 합니다 Insert 작업 합니다.

삽입 단추를 Insert 클릭하면 속성에 지정된 메서드와 컬렉션에 InsertMethod 지정된 매개 변수를 사용하여 작업이 수행됩니다InsertParameters. 이 코드 예제에서는 하나의 매개 변수는에 지정 된 된 InsertParameters 감독자의 ID에 해당 하는 컬렉션 ID에 표시 되는 경우에 이므로이 Fields 컬렉션에 대 한는 DetailsView 컨트롤을 BoundField 개체에 문자열로 전달 됩니다는 ObjectDataSource 컨트롤. 명시적으로 추가 하 여는 InsertParameters 사용 하 여 컬렉션을 Type 로 설정 된 속성을 Int32 값으로 전달 됩니다에서 올바르게를 ObjectDataSource 메서드에으로 int, 아니라 string.

경우는 Insert 작업을 수행할로 식별 되는 메서드는 InsertMethod 속성 이라고 합니다. 경우는 Insert 개체의 메서드가 매개 변수를 포함 하는 메서드 시그니처를 InsertParameters 컬렉션에 대 한 메서드 시그니처 매개 변수와 일치 하는 이름 가진 매개 변수가 포함 되어야 합니다는 Insert 성공적으로 완료 합니다.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS" Assembly="Samples.AspNet.CS" %>
<%@ Import namespace="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"
          autogenerateinsertbutton="True"
          autogeneraterows="false"
          datasourceid="ObjectDataSource1"
          defaultmode="Insert" >
          <fields>
            <asp:BoundField headertext="FirstName" datafield="FirstName" />
            <asp:BoundField headertext="LastName"   datafield="LastName" />
            <asp:BoundField headertext="Title"      datafield="Title" />
            <asp:BoundField headertext="Courtesy"   datafield="Courtesy" />
            <asp:BoundField headertext="Supervisor" datafield="Supervisor" />
          </fields>
        </asp:detailsview>

        <asp:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetEmployee"
          insertmethod="InsertNewEmployeeWrapper"
          typename="Samples.AspNet.CS.EmployeeLogic" >
          <selectparameters>
            <asp:parameter name="anID" defaultvalue="-1" />
          </selectparameters>
          <insertparameters>
            <asp:parameter name="Supervisor" type="Int32" />
          </insertparameters>
        </asp:objectdatasource>

    </form>
  </body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB" Assembly="Samples.AspNet.VB" %>
<%@ Import namespace="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"
          autogenerateinsertbutton="True"
          autogeneraterows="false"
          datasourceid="ObjectDataSource1"
          defaultmode="Insert" >
          <fields>
            <asp:BoundField headertext="FirstName" datafield="FirstName" />
            <asp:BoundField headertext="LastName"   datafield="LastName" />
            <asp:BoundField headertext="Title"      datafield="Title" />
            <asp:BoundField headertext="Courtesy"   datafield="Courtesy" />
            <asp:BoundField headertext="Supervisor" datafield="Supervisor" />
          </fields>
        </asp:detailsview>

        <asp:objectdatasource
          id="ObjectDataSource1"
          runat="server"
          selectmethod="GetEmployee"
          insertmethod="InsertNewEmployeeWrapper"
          typename="Samples.AspNet.VB.EmployeeLogic" >
          <selectparameters>
            <asp:parameter name="anID" defaultvalue="-1" />
          </selectparameters>
          <insertparameters>
            <asp:parameter name="Supervisor" type="Int32" />
          </insertparameters>
        </asp:objectdatasource>

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

다음 코드 예제에서는의 예제 구현을 제공 합니다 Insert 앞의 코드 예제를 사용 하는 메서드. 합니다 InsertNewEmployeeWrapper 메서드가 추가 되는 EmployeeLogic 개체를 보다 쉽게 작업할 수 있도록 중간 계층 개체를 ObjectDataSource 실제 비즈니스 논리를 쓰지 않고도 웹 시나리오에서.

// This InsertNewEmployeeWrapper method is a wrapper method that enables
// the use of ObjectDataSource and InsertParameters, without
// substantially rewriting the true implementation for the NorthwindEmployee
// or the EmployeeLogic objects.
//
// The parameters to the method must be named the same as the
// DataControlFields used by the GridView or DetailsView controls.
public static void InsertNewEmployeeWrapper (string FirstName,
                                             string LastName,
                                             string Title,
                                             string Courtesy,
                                             int    Supervisor)
{
  // Build the NorthwindEmployee object and
  // call the true  implementation.
  NorthwindEmployee tempEmployee = new NorthwindEmployee();

  tempEmployee.FirstName  = FirstName;
  tempEmployee.LastName   = LastName;
  tempEmployee.Title      = Title;
  tempEmployee.Courtesy   = Courtesy;
  tempEmployee.Supervisor = Supervisor;

  // Call the true implementation.
  InsertNewEmployee(tempEmployee);
}

public static void InsertNewEmployee(NorthwindEmployee ne) {
  bool retval = ne.Save();
  if (! retval) { throw new NorthwindDataException("InsertNewEmployee failed."); }
}
' This InsertNewEmployeeWrapper method is a wrapper method that enables
' the use of ObjectDataSource and InsertParameters, without
' substantially rewriting the true implementation for the NorthwindEmployee
' or the EmployeeLogic objects.
'
' The parameters to the method must be named the same as the
' DataControlFields used by the GridView or DetailsView controls.
Public Shared Sub InsertNewEmployeeWrapper(FirstName As String, LastName As String, Title As String, Courtesy As String, Supervisor As Integer)
   ' Build the NorthwindEmployee object and
   ' call the true  implementation.
   Dim tempEmployee As New NorthwindEmployee()

   tempEmployee.FirstName = FirstName
   tempEmployee.LastName = LastName
   tempEmployee.Title = Title
   tempEmployee.Courtesy = Courtesy
   tempEmployee.Supervisor = Supervisor

   ' Call the true implementation.
   InsertNewEmployee(tempEmployee)
End Sub


Public Shared Sub InsertNewEmployee(ne As NorthwindEmployee)
   Dim retval As Boolean = ne.Save()
   If Not retval Then
      Throw New NorthwindDataException("InsertNewEmployee failed.")
   End If
End Sub

설명

이름 및 형식에 포함 된 매개 변수를 InsertParameters 컬렉션에 지정 된 메서드는 매개 변수의 형식과 이름 일치 해야 합니다는 InsertMethod 속성 서명. 와 같은 매개 변수를 제공 하는 데이터 바인딩된 컨트롤을 사용 하는 경우 GridView 하 고 DetailsView, ObjectDataSource 컨트롤에서 제공 하는 이러한 매개 변수를 사용 하 여 컬렉션에 명시적으로 지정 된 매개 변수를 자동으로 병합 데이터 바인딩된 컨트롤입니다. 자세한 내용은 InsertMethod를 참조하세요.

적용 대상

추가 정보