ListViewUpdatedEventArgs 클래스

정의

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

public ref class ListViewUpdatedEventArgs : EventArgs
public class ListViewUpdatedEventArgs : EventArgs
type ListViewUpdatedEventArgs = class
    inherit EventArgs
Public Class ListViewUpdatedEventArgs
Inherits EventArgs
상속
ListViewUpdatedEventArgs

예제

다음 예제에서는 사용 하는 방법의 ListViewUpdatedEventArgs 업데이트 작업 중에 예외가 발생 했는지 여부를 결정 하는 개체입니다.

중요

이 예제에는 사용자 입력을 허용하는 텍스트 상자가 있으므로 보안상 위험할 수 있습니다. 기본적으로 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 ContactsListView_ItemUpdated(Object sender, ListViewUpdatedEventArgs e)
    {
        if (e.Exception != null)
        {
            if (e.AffectedRows == 0)
            {
                e.KeepInEditMode = true;
                Message.Text = "An exception occurred updating the contact. " +
                                    "Please verify your values and try again.";
            }
            else
                Message.Text = "An exception occurred updating the contact. " +
                                    "Please verify the values in the recently updated item.";

            e.ExceptionHandled = true;
        }
    }
   //</Snippet2>
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>ListView.ItemUpdated Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>ListView.ItemUpdated Example</h3>
            
      <asp:Label ID="Message"
        ForeColor="Red"          
        runat="server"/>
      <br/>

      <asp:ListView ID="ContactsListView" 
        DataSourceID="ContactsDataSource" 
        DataKeyNames="ContactID"
        OnItemUpdated="ContactsListView_ItemUpdated"  
        runat="server">
        <LayoutTemplate>
          <table cellpadding="2" border="1" runat="server" id="tblContacts" width="640px">
            <tr runat="server" id="itemPlaceholder" />
          </table>
          <asp:DataPager runat="server" ID="PeopleDataPager" 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:Label ID="FirstNameLabel" runat="server" Text='<%#Eval("FirstName") %>' />
                <asp:Label ID="LastNameLabel" runat="server" Text='<%#Eval("LastName") %>' />
              </td>
              <td>
                <asp:Label ID="EmailLabel" runat="server" Text='<%#Eval("EmailAddress") %>' />
              </td>
              <td>
                <asp:LinkButton ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
              </td>
            </tr>
          </ItemTemplate>
          <EditItemTemplate>
            <tr style="background-color:#ADD8E6">
              <td valign="top">
                <asp:Label runat="server" ID="FirstNameLabel" 
                  AssociatedControlID="FirstNameTextBox" Text="First Name"/>
                <asp:TextBox ID="FirstNameTextBox" runat="server"
                  Text='<%# Bind("FirstName") %>' MaxLength="50" Width="200px" /><br />
                <asp:Label runat="server" ID="LastNameLabel" 
                  AssociatedControlID="LastNameTextBox" Text="Last Name" />
                <asp:TextBox ID="LastNameTextBox" runat="server" 
                  Text='<%# Bind("LastName") %>' MaxLength="50" Width="200px" /><br />
                <asp:Label runat="server" ID="EmailLabel" 
                  AssociatedControlID="EmailTextBox" Text="Email" />
                <asp:TextBox ID="EmailTextBox" runat="server" 
                  Text='<%# Bind("EmailAddress") %>' MaxLength="50" Width="200px" />
              </td>
              <td colspan="2" valign="top">
                <asp:LinkButton ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
                <asp:LinkButton ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
              </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="ContactsDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
        SelectCommand="SELECT [ContactID], [FirstName], [LastName], [EmailAddress] 
          FROM Person.Contact"
        UpdateCommand="UPDATE Person.Contact
          Set [FirstName] = @FirstName, [LastName] = @LastName, [EmailAddress] = @EmailAddress 
          WHERE [ContactID] = @ContactID">
      </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 ContactsListView_ItemUpdated(sender As Object, e As ListViewUpdatedEventArgs)
        If e.Exception IsNot Nothing Then
            If e.AffectedRows = 0 Then
                e.KeepInEditMode = True
                Message.Text = "An exception occurred updating the contact. " & _
                                    "Please verify your values and try again."
            Else
                Message.Text = "An exception occurred updating the contact. " & _
                                    "Please verify the values in the recently updated item."
            End If

            e.ExceptionHandled = True
        End If
    End Sub
   '</Snippet2>
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>ListView.ItemUpdated Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>ListView.ItemUpdated Example</h3>
            
      <asp:Label ID="Message"
        ForeColor="Red"          
        runat="server"/>
      <br/>

      <asp:ListView ID="ContactsListView" 
        DataSourceID="ContactsDataSource" 
        DataKeyNames="ContactID"
        OnItemUpdated="ContactsListView_ItemUpdated"  
        runat="server">
        <LayoutTemplate>
          <table cellpadding="2" border="1" runat="server" id="tblContacts" width="640px">
            <tr runat="server" id="itemPlaceholder" />
          </table>
          <asp:DataPager runat="server" ID="PeopleDataPager" 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>
              <td valign="top">
                <asp:Label ID="FirstNameLabel" runat="server" Text='<%#Eval("FirstName") %>' />
                <asp:Label ID="LastNameLabel" runat="server" Text='<%#Eval("LastName") %>' />
              </td>
              <td>
                <asp:Label ID="EmailLabel" runat="server" Text='<%#Eval("EmailAddress") %>' />
              </td>
              <td>
                <asp:LinkButton ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
              </td>
            </tr>
          </ItemTemplate>
          <EditItemTemplate>
            <tr style="background-color:#ADD8E6">
              <td valign="top">
                <asp:Label runat="server" ID="FirstNameLabel" 
                  AssociatedControlID="FirstNameTextBox" Text="First Name"/>
                <asp:TextBox ID="FirstNameTextBox" runat="server"
                  Text='<%# Bind("FirstName") %>' MaxLength="50" Width="200px" /><br />
                <asp:Label runat="server" ID="LastNameLabel" 
                  AssociatedControlID="LastNameTextBox" Text="Last Name" />
                <asp:TextBox ID="LastNameTextBox" runat="server" 
                  Text='<%# Bind("LastName") %>' MaxLength="50" Width="200px" /><br />
                <asp:Label runat="server" ID="EmailLabel" 
                  AssociatedControlID="EmailTextBox" Text="Email" />
                <asp:TextBox ID="EmailTextBox" runat="server" 
                  Text='<%# Bind("EmailAddress") %>' MaxLength="50" Width="200px" />
              </td>
              <td colspan="2" valign="top">
                <asp:LinkButton ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
                <asp:LinkButton ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
              </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="ContactsDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
        SelectCommand="SELECT [ContactID], [FirstName], [LastName], [EmailAddress] 
          FROM Person.Contact"
        UpdateCommand="UPDATE Person.Contact
          Set [FirstName] = @FirstName, [LastName] = @LastName, [EmailAddress] = @EmailAddress 
          WHERE [ContactID] = @ContactID">
      </asp:SqlDataSource>
      
    </form>
  </body>
</html>

설명

ListView 를 발생 시킵니다 합니다 ItemUpdated 이벤트 때를 UpdateItem 메서드를 호출 하거나 컨트롤의 업데이트 단추를 클릭할 때, 한 후를 ListView 컨트롤에서 항목을 업데이트 합니다. (업데이트 단추는 단추입니다 CommandName 속성을 "Update"로 설정 합니다.) 이 업데이트 작업의 결과 확인 하는 등이 이벤트가 발생할 때마다 사용자 지정 루틴을 수행 하는 이벤트 처리 메서드를 제공할 수 있습니다.

ListViewUpdatedEventArgs 개체 이벤트 처리 메서드에 전달 됩니다. 이 개체를 사용 하면 업데이트 된 항목의 수를 확인 하 고 발생 했을 수 있는 모든 예외를 가져올 수 있습니다. 업데이트 작업으로 영향을 받는 항목의 수를 확인 하려면 사용 된 AffectedRows 속성입니다. 예외 발생 했는지 여부를 확인 하려면 사용 된 Exception 속성입니다. 설정 하 여 이벤트 처리 메서드에서 예외가 처리 되었는지 여부를 지정할 수 있습니다는 ExceptionHandled 속성입니다. 필드의 원래 값을 사용 하 여 액세스할 수 있습니다는 OldValues 속성입니다. 사용 하 여 업데이트 된 필드 값에 액세스할 수 있습니다는 NewValues 속성입니다.

기본적으로 ListView 항목 업데이트 작업 후 읽기 전용 모드로 돌아갑니다. 업데이트 작업 중에 발생 한 예외를 처리 하는 경우 유지할 수 있습니다 합니다 ListView 항목을 설정 하 여 편집 모드에는 KeepInEditMode 속성을 true입니다.

ListViewUpdatedEventArgs 클래스의 인스턴스에 대한 초기 속성 값 목록은 ListViewUpdatedEventArgs 생성자를 참조하십시오.

생성자

ListViewUpdatedEventArgs(Int32, Exception)

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

속성

AffectedRows

업데이트 작업의 영향을 받는 행의 수를 가져옵니다.

Exception

업데이트 작업 중에 발생한 예외(있을 경우)를 가져옵니다.

ExceptionHandled

업데이트 작업 중에 발생한 예외가 이벤트 발생 도중 처리되었는지 여부를 나타내는 값을 가져오거나 설정합니다.

KeepInEditMode

업데이트 작업 후 ListView 컨트롤을 편집 모드로 유지할지 여부를 나타내는 값을 가져오거나 설정합니다.

NewValues

업데이트된 항목의 새 값이 들어 있는 사전을 가져옵니다.

OldValues

업데이트된 항목의 원래 값이 들어 있는 사전을 가져옵니다.

메서드

Equals(Object)

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

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

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

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

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

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

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

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

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

(다음에서 상속됨 Object)

적용 대상

추가 정보