ListViewEditEventArgs 클래스

정의

ItemEditing 이벤트에 대한 데이터를 제공합니다.

public ref class ListViewEditEventArgs : System::ComponentModel::CancelEventArgs
public class ListViewEditEventArgs : System.ComponentModel.CancelEventArgs
type ListViewEditEventArgs = class
    inherit CancelEventArgs
Public Class ListViewEditEventArgs
Inherits CancelEventArgs
상속
ListViewEditEventArgs

예제

다음 예제에서는 사용 하는 방법의 ListViewEditEventArgs 사용자가 지원 되지 않는 항목을 업데이트 하려고 할 때 편집 작업을 취소 하는 개체입니다.

중요

이 예제에는 사용자 입력을 허용하는 텍스트 상자가 있으므로 보안상 위험할 수 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.

<%@ 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 Page_Load()
  {
    Message.Text = String.Empty;
  }

  //<Snippet2>
  void ProductsListView_ItemEditing(Object sender, ListViewEditEventArgs e)
  {
    ListViewItem item = ProductsListView.Items[e.NewEditIndex];
    Label dateLabel = (Label)item.FindControl("DiscontinuedDateLabel");
    
    if (String.IsNullOrEmpty(dateLabel.Text))
      return;
    
    //Verify if the item is discontinued.
    DateTime discontinuedDate = DateTime.Parse(dateLabel.Text);
    if (discontinuedDate < DateTime.Now)
    {
      Message.Text = "You cannot edit a discontinued item.";
      e.Cancel = true;
      ProductsListView.SelectedIndex = -1;
    }       
  }
  //</Snippet2>

  void DiscontinuedDateCalendar_OnSelectionChanged(Object sender, EventArgs e)
  {
    TextBox dateTextBox = 
      (TextBox)ProductsListView.EditItem.FindControl("DiscontinuedDateTextBox");
    Calendar calendarObject = (Calendar)sender;
    dateTextBox.Text = calendarObject.SelectedDate.ToString("d");
  }

  DateTime GetDateTime(object dateValue)
  {
    if (dateValue == DBNull.Value)
      return DateTime.Now;
    else
      return (DateTime)dateValue;
  }

  protected void ProductsListView_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
  {
    // Clears the edit index selection when paging.
    ProductsListView.EditIndex = -1;
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>ListView Edit Item Example</title>
  </head>
  <body>
    <form id="form1" runat="server">
        
      <h3>ListView Edit Item Example</h3>
            
      <asp:Label ID="Message"
        ForeColor="Red"          
        runat="server"/>
      <br/>
     
      <asp:ListView ID="ProductsListView" 
        DataSourceID="ProductsDataSource" 
        DataKeyNames="ProductID"
        OnItemEditing="ProductsListView_ItemEditing" 
        ConvertEmptyStringToNull="true"        
        OnPagePropertiesChanging="ProductsListView_PagePropertiesChanging"
        runat="server" >
        <LayoutTemplate>
          <table cellpadding="2" runat="server" id="tblProducts" width="640px">
            <tr runat="server" id="itemPlaceholder" />
          </table>
          <asp:DataPager runat="server" ID="ProductsDataPager" PageSize="12">
            <Fields>
              <asp:NextPreviousPagerField 
                ShowFirstPageButton="true" ShowLastPageButton="true"
                FirstPageText="|&lt;&lt; " LastPageText=" &gt;&gt;|"
                NextPageText=" &gt; " PreviousPageText=" &lt; " />
            </Fields>
          </asp:DataPager>
        </LayoutTemplate>
        <ItemTemplate>
          <tr runat="server">
            <td valign="top">
              <asp:LinkButton ID="EditButton" runat="server" Text="Edit" CommandName="Edit" />
            </td>
            <td valign="top">
              <asp:Label ID="NameLabel" runat="server" Text='<%#Eval("Name") %>' />
            </td>
            <td valign="top">
              <asp:Label ID="ProductNumberLabel" runat="server" Text='<%#Eval("ProductNumber") %>' />
            </td>
            <td>
              <asp:Label ID="DiscontinuedDateLabel" runat="server" 
                Text='<%#Eval("DiscontinuedDate", "{0:d}") %>' />
            </td>
          </tr>
        </ItemTemplate>
        <EditItemTemplate>
          <tr style="background-color:#ADD8E6">
            <td valign="top">
              <asp:LinkButton ID="UpdateButton" runat="server" 
                CommandName="Update" Text="Update" /><br />
              <asp:LinkButton ID="CancelButton" runat="server" 
                CommandName="Cancel" Text="Cancel" />
            </td>
            <td valign="top" colspan="2">
              <asp:Label runat="server" ID="NameLabel" 
                AssociatedControlID="NameTextBox" 
                Text="Name"/>
              <asp:TextBox ID="NameTextBox" runat="server" 
                Text='<%#Bind("Name") %>' MaxLength="50" /><br />
              <asp:Label runat="server" ID="ProductNumberLabel" 
                AssociatedControlID="ProductNumberTextBox" 
                Text="Product Number" />
              <asp:TextBox ID="ProductNumberTextBox" runat="server" 
                Text='<%#Bind("ProductNumber") %>' MaxLength="25" /><br />
            </td>
            <td>
              <asp:Label runat="server" ID="DiscontinuedDateLabel" 
                AssociatedControlID="DiscontinuedDateTextBox" 
                Text="Discontinued Date"/>
              <asp:TextBox ID="DiscontinuedDateTextBox" runat="server" 
                Text='<%# Bind("DiscontinuedDate", "{0:d}") %>'
                MaxLength="10" /><br />
              <asp:Calendar ID="DiscontinuedDateCalendar" runat="server" 
                SelectedDate='<%# GetDateTime(Eval("DiscontinuedDate")) %>'
                OnSelectionChanged="DiscontinuedDateCalendar_OnSelectionChanged" />
            </td>
          </tr>
        </EditItemTemplate>
      </asp:ListView>

      <!-- This example uses Microsoft SQL Server and connects      -->
      <!-- to the AdventureWorks sample database. Use an ASP.NET    -->
      <!-- expression to retrieve the connection string value       -->
      <!-- from the Web.config file.                                -->            
      <asp:SqlDataSource ID="ProductsDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
        SelectCommand="SELECT [ProductID], [Name], [ProductNumber], [DiscontinuedDate] 
          FROM Production.Product"
        UpdateCommand="UPDATE Production.Product
          SET Name = @Name, ProductNumber = @ProductNumber, DiscontinuedDate = @DiscontinuedDate
          WHERE ProductID = @ProductID">
      </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 Page_Load()
    Message.Text = String.Empty
  End Sub
  
  '<Snippet2>
  Sub ProductsListView_ItemEditing(ByVal sender As Object, ByVal e As ListViewEditEventArgs)
    Dim item As ListViewItem = ProductsListView.Items(e.NewEditIndex)
    Dim dateLabel As Label = CType(item.FindControl("DiscontinuedDateLabel"), Label)
      
    If String.IsNullOrEmpty(dateLabel.Text) Then _
      Return
      
    'Verify if the item is discontinued.
    Dim discontinuedDate As DateTime = DateTime.Parse(dateLabel.Text)
    If discontinuedDate < DateTime.Now Then
      Message.Text = "You cannot edit a discontinued item."
      e.Cancel = True
      ProductsListView.SelectedIndex = -1
    End If
  End Sub
  '</Snippet2>
  
  Sub DiscontinuedDateCalendar_OnSelectionChanged(ByVal sender As Object, ByVal e As EventArgs)
    Dim dateTextBox As TextBox = _
      CType(ProductsListView.EditItem.FindControl("DiscontinuedDateTextBox"), TextBox)
    Dim calendarObject As Calendar = CType(sender, Calendar)
    dateTextBox.Text = calendarObject.SelectedDate.ToString("d")
  End Sub

  Function GetDateTime(ByVal dateValue As Object) As DateTime
    If dateValue Is DBNull.Value Then
      Return DateTime.Now
    Else
      Return CType(dateValue, DateTime)
    End If
  End Function
  
  Protected Sub ProductsListView_PagePropertiesChanging(ByVal sender As Object, _
                                               ByVal e As PagePropertiesChangingEventArgs)
    ' Clears the edit index selection when paging.
    ProductsListView.EditIndex = -1
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>ListView Edit Item Example</title>
  </head>
  <body>
    <form id="form1" runat="server">
        
      <h3>ListView Edit Item Example</h3>
            
      <asp:Label ID="Message"
        ForeColor="Red"          
        runat="server"/>
      <br/>
     
      <asp:ListView ID="ProductsListView" 
        DataSourceID="ProductsDataSource" 
        DataKeyNames="ProductID"
        OnItemEditing="ProductsListView_ItemEditing" 
        ConvertEmptyStringToNull="true"        
        OnPagePropertiesChanging="ProductsListView_PagePropertiesChanging"
        runat="server" >
        <LayoutTemplate>
          <table cellpadding="2" runat="server" id="tblProducts" width="640px">
            <tr runat="server" id="itemPlaceholder" />
          </table>
          <asp:DataPager runat="server" ID="ProductsDataPager" PageSize="12">
            <Fields>
              <asp:NextPreviousPagerField 
                ShowFirstPageButton="true" ShowLastPageButton="true"
                FirstPageText="|&lt;&lt; " LastPageText=" &gt;&gt;|"
                NextPageText=" &gt; " PreviousPageText=" &lt; " />
            </Fields>
          </asp:DataPager>
        </LayoutTemplate>
        <ItemTemplate>
          <tr runat="server">
            <td valign="top">
              <asp:LinkButton ID="EditButton" runat="server" Text="Edit" CommandName="Edit" />
            </td>
            <td valign="top">
              <asp:Label ID="NameLabel" runat="server" Text='<%#Eval("Name") %>' />
            </td>
            <td valign="top">
              <asp:Label ID="ProductNumberLabel" runat="server" Text='<%#Eval("ProductNumber") %>' />
            </td>
            <td>
              <asp:Label ID="DiscontinuedDateLabel" runat="server" 
                Text='<%#Eval("DiscontinuedDate", "{0:d}") %>' />
            </td>
          </tr>
        </ItemTemplate>
        <EditItemTemplate>
          <tr style="background-color:#ADD8E6">
            <td valign="top">
              <asp:LinkButton ID="UpdateButton" runat="server" 
                CommandName="Update" Text="Update" /><br />
              <asp:LinkButton ID="CancelButton" runat="server" 
                CommandName="Cancel" Text="Cancel" />
            </td>
            <td valign="top" colspan="2">
              <asp:Label runat="server" ID="NameLabel" 
                AssociatedControlID="NameTextBox" 
                Text="Name"/>
              <asp:TextBox ID="NameTextBox" runat="server" 
                Text='<%#Bind("Name") %>' MaxLength="50" /><br />
              <asp:Label runat="server" ID="ProductNumberLabel" 
                AssociatedControlID="ProductNumberTextBox" 
                Text="Product Number" />
              <asp:TextBox ID="ProductNumberTextBox" runat="server" 
                Text='<%#Bind("ProductNumber") %>' MaxLength="25" /><br />
            </td>
            <td>
              <asp:Label runat="server" ID="DiscontinuedDateLabel" 
                AssociatedControlID="DiscontinuedDateTextBox" 
                Text="Discontinued Date"/>
              <asp:TextBox ID="DiscontinuedDateTextBox" runat="server" 
                Text='<%# Bind("DiscontinuedDate", "{0:d}") %>'
                MaxLength="10" /><br />
              <asp:Calendar ID="DiscontinuedDateCalendar" runat="server" 
                SelectedDate='<%# GetDateTime(Eval("DiscontinuedDate")) %>'
                OnSelectionChanged="DiscontinuedDateCalendar_OnSelectionChanged" />
            </td>
          </tr>
        </EditItemTemplate>
      </asp:ListView>

      <!-- This example uses Microsoft SQL Server and connects      -->
      <!-- to the AdventureWorks sample database. Use an ASP.NET    -->
      <!-- expression to retrieve the connection string value       -->
      <!-- from the Web.config file.                                -->            
      <asp:SqlDataSource ID="ProductsDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
        SelectCommand="SELECT [ProductID], [Name], [ProductNumber], [DiscontinuedDate] 
          FROM Production.Product"
        UpdateCommand="UPDATE Production.Product
          SET Name = @Name, ProductNumber = @ProductNumber, DiscontinuedDate = @DiscontinuedDate
          WHERE ProductID = @ProductID">
      </asp:SqlDataSource>
      
    </form>
  </body>
</html>

설명

ListView 를 발생 시킵니다 합니다 ItemEditing 이벤트 편집 단추를 클릭 하면 하기 전에 ListView 항목이 편집 모드로 전환 합니다. (편집 단추는 단추입니다 CommandName 속성이 "Edit"로 설정 합니다.) 그러면 편집 작업을 취소 하는 등이 이벤트가 발생할 때마다 사용자 지정 루틴을 수행 하는 이벤트 처리 메서드를 제공할 수 있습니다.

ListViewEditEventArgs 개체 이벤트 처리 메서드에 전달 됩니다. 이 개체를 사용 하 여 편집 중인 항목의 인덱스를 확인 하 고 편집 작업을 취소 해야 함을 나타낼 수 있습니다. 편집 작업을 취소 하려면 합니다 Cancel 의 속성을 ListViewEditEventArgs 개체를 true입니다.

인스턴스의 초기 속성 값의 목록을 ListViewEditEventArgs, 참조는 ListViewEditEventArgs 생성자입니다.

생성자

ListViewEditEventArgs(Int32)

ListViewEditEventArgs 클래스의 새 인스턴스를 초기화합니다.

속성

Cancel

이벤트를 취소해야 할지 여부를 나타내는 값을 가져오거나 설정합니다.

(다음에서 상속됨 CancelEventArgs)
NewEditIndex

편집 중인 항목의 인덱스를 가져옵니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보