GridView.DeleteRow(Int32) 메서드

정의

데이터 원본에서 지정된 인덱스의 레코드를 삭제합니다.

public:
 virtual void DeleteRow(int rowIndex);
public virtual void DeleteRow(int rowIndex);
abstract member DeleteRow : int -> unit
override this.DeleteRow : int -> unit
Public Overridable Sub DeleteRow (rowIndex As Integer)

매개 변수

rowIndex
Int32

삭제할 행의 인덱스입니다.

예외

컨트롤이 GridView 데이터 원본 컨트롤에 바인딩되지 않습니다.

컨트롤이 GridView 바인딩된 데이터 원본 컨트롤은 삭제 작업을 지원하지 않거나 데이터 원본에 대해 정의된 삭제 명령이 없습니다.

예제

다음 예제에서는 프로그래밍 방식으로 컨트롤에서 DeleteRow 레코드를 삭제 하는 메서드를 사용 하는 방법을 보여 줍니다 GridView .


<%@ 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 DeleteRowButton_Click(Object sender, EventArgs e)
  {
    // Programmatically delete the selected record.
    CustomersGridView.DeleteRow(CustomersGridView.SelectedIndex);
  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridView DeleteRow Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView DeleteRow Example</h3>

      <asp:button id="DeleteRowButton"
        text="Delete Record"
        onclick="DeleteRowButton_Click" 
        runat="server"/>

      <hr/>

      <asp:gridview id="CustomersGridView" 
        allowpaging="true"
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="true"
        autogenerateselectbutton="true"
        datakeynames="CustomerID"
        selectedindex="0"   
        runat="server">
        
        <selectedrowstyle BackColor="lightblue"/>
        
      </asp:gridview>
            
      <!-- 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="CustomersSqlDataSource"  
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
        deletecommand="Delete from Customers where CustomerID = @CustomerID"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
    </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 DeleteRowButton_Click(sender As Object, e As EventArgs)
 
    ' Programmatically delete the selected record.
    CustomersGridView.DeleteRow(CustomersGridView.SelectedIndex)
    
  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridView DeleteRow Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView DeleteRow Example</h3>

      <asp:button id="DeleteRowButton"
        text="Delete Record"
        onclick="DeleteRowButton_Click" 
        runat="server"/>

      <hr/>

      <asp:gridview id="CustomersGridView" 
        allowpaging="true"
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="true"
        autogenerateselectbutton="true"
        datakeynames="CustomerID"
        selectedindex="0"   
        runat="server">
        
        <selectedrowstyle BackColor="lightblue"/>
        
      </asp:gridview>
            
      <!-- 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="CustomersSqlDataSource"  
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
        deletecommand="Delete from Customers where CustomerID = @CustomerID"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

설명

이 메서드를 DeleteRow 사용하여 데이터 원본에서 지정된 인덱스에서 레코드를 프로그래밍 방식으로 삭제합니다. 이 메서드는 일반적으로 페이지의 다른 컨트롤에서와 같이 컨트롤 외부에서 GridView 레코드를 삭제 해야 하는 경우에 사용 됩니다. 이 메서드를 호출하면 이벤트 및 RowDeleted 이벤트도 발생합니다RowDeleting.

적용 대상

추가 정보