다음을 통해 공유


FormView.DeleteItem 메서드

정의

데이터 소스에서 FormView 컨트롤의 현재 레코드를 삭제합니다.

public:
 virtual void DeleteItem();
public virtual void DeleteItem ();
abstract member DeleteItem : unit -> unit
override this.DeleteItem : unit -> unit
Public Overridable Sub DeleteItem ()

예제

다음 예제에서는 사용 하는 방법을 보여 줍니다.는 DeleteItem 프로그래밍 방식으로 삭제 하는 메서드를 데이터 원본에서 컨트롤의 FormView 현재 레코드입니다.


<%@ 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">
  
  void DeleteButton_Click(Object sender, EventArgs e)
  {

    // Use the DeleteItem method to programmatically delete
    // the current record in the FormView control. 
    EmployeeFormView.DeleteItem();

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>FormView DeleteItem Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>FormView DeleteItem Example</h3>
                       
      <asp:formview id="EmployeeFormView"
        datasourceid="EmployeeSource"
        allowpaging="true"
        datakeynames="EmployeeID" 
        runat="server">
        
        <itemtemplate>
        
          <table>
            <tr>
              <td>
                <asp:image id="EmployeeImage"
                  imageurl='<%# Eval("PhotoPath") %>'
                  alternatetext='<%# Eval("LastName") %>' 
                  runat="server"/>
              </td>
              <td>
                <h3><%# Eval("FirstName") %> <%# Eval("LastName") %></h3>      
                <%# Eval("Title") %>        
              </td>
            </tr>
          </table>
        
        </itemtemplate>
          
      </asp:formview>
      
      <hr/>
      
      <asp:Button id="DeleteButton"
        text="Delete Record"
        onclick="DeleteButton_Click" 
        runat="server"/>
          
      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file.                            -->
      <asp:sqldatasource id="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [PhotoPath] From [Employees]"
        deletecommand="Delete [Employees] Where [EmployeeID]=@EmployeeID"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
            
    </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">
  
  Sub DeleteButton_Click(ByVal sender As Object, ByVal e As EventArgs)

    ' Use the DeleteItem method to programmatically delete
    ' the current record in the FormView control. 
    EmployeeFormView.DeleteItem()

  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>FormView DeleteItem Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>FormView DeleteItem Example</h3>
                       
      <asp:formview id="EmployeeFormView"
        datasourceid="EmployeeSource"
        allowpaging="true"
        datakeynames="EmployeeID" 
        runat="server">
        
        <itemtemplate>
        
          <table>
            <tr>
              <td>
                <asp:image id="EmployeeImage"
                  imageurl='<%# Eval("PhotoPath") %>'
                  alternatetext='<%# Eval("LastName") %>' 
                  runat="server"/>
              </td>
              <td>
                <h3><%# Eval("FirstName") %> <%# Eval("LastName") %></h3>      
                <%# Eval("Title") %>        
              </td>
            </tr>
          </table>
        
        </itemtemplate>
          
      </asp:formview>
      
      <hr/>
      
      <asp:Button id="DeleteButton"
        text="Delete Record"
        onclick="DeleteButton_Click" 
        runat="server"/>
          
      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file.                            -->
      <asp:sqldatasource id="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [PhotoPath] From [Employees]"
        deletecommand="Delete [Employees] Where [EmployeeID]=@EmployeeID"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
            
    </form>
  </body>
</html>

설명

메서드를 DeleteItem 사용하여 데이터 원본에서 컨트롤의 현재 레코드를 FormView 프로그래밍 방식으로 삭제합니다. 이 메서드는 페이지의 다른 컨트롤과 같이 컨트롤 외부에서 현재 레코드를 FormView 삭제해야 하는 경우에 일반적으로 사용됩니다. 이 메서드를 호출하면 및 ItemDeleting 이벤트도 발생합니다ItemDeleted.

적용 대상

추가 정보