다음을 통해 공유


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 속성에서 사용하는 매개 변수를 InsertMethod 포함하는 A입니다.

예제

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

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

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

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 메서드에 있는 매개 변수의 이름 및 형식과 일치해야 합니다. 같은 GridViewDetailsViewObjectDataSource 매개 변수를 제공하는 데이터 바인딩된 컨트롤을 사용하는 경우 컨트롤은 컬렉션에 명시적으로 지정된 모든 매개 변수를 데이터 바인딩된 컨트롤에서 제공하는 매개 변수와 자동으로 병합합니다. 자세한 내용은 InsertMethod를 참조하세요.

적용 대상

추가 정보