ListViewInsertedEventArgs 클래스

정의

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

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

예제

다음 예제에서는 사용 하는 방법을 보여 줍니다 합니다 ListViewInsertedEventArgs 이벤트의 처리기에 전달 되는 개체는 ItemInserted 이벤트입니다.

중요

이 예제에는 사용자 입력을 허용하는 텍스트 상자가 있으므로 보안상 위험할 수 있습니다. 기본적으로 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">

  //<Snippet3>
  void ContactsListView_ItemInserted(Object sender, ListViewInsertedEventArgs e)
  {
    if (e.Exception != null)
    {
      if (e.AffectedRows == 0)
      {
        e.KeepInInsertMode = true;
        Message.Text = "An exception occurred inserting the new Contact. " +
          "Please verify your values and try again.";
      }
      else
        Message.Text = "An exception occurred inserting the new Contact. " +
          "Please verify the values in the newly inserted item.";

      e.ExceptionHandled = true;
    }
  }
  //</Snippet3>

  protected void Page_Load(object sender, EventArgs e)
  {
    Message.Text = "";
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>ListView.ItemInserted Example</title>
  </head>
  <body>
    <form id="form1" runat="server">
        
      <h3>ListViewItemInserted Example</h3>
            
      <asp:Label ID="Message"
        ForeColor="Red"          
        runat="server"/>
      <br/>
      
      <asp:ListView ID="ContactsListView" 
        DataSourceID="ContactsDataSource" 
        DataKeyNames="ContactID"
        OnItemInserted="ContactsListView_ItemInserted"  
        InsertItemPosition="LastItem"
        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>&nbsp;
              <asp:Label ID="EmailLabel" runat="server" Text='<%#Eval("EmailAddress") %>' />
            </td>
          </tr>
        </ItemTemplate>
        <InsertItemTemplate>
          <tr style="background-color:#D3D3D3">
            <td valign="top">
              <asp:Label runat="server" ID="FirstNameLabel" 
                AssociatedControlID="FirstNameTextBox" Text="First Name"/>
              <asp:TextBox ID="FirstNameTextBox" runat="server" 
                Text='<%#Bind("FirstName") %>' /><br />
              <asp:Label runat="server" ID="LastNameLabel" 
                AssociatedControlID="LastNameTextBox" Text="Last Name" />
              <asp:TextBox ID="LastNameTextBox" runat="server" 
                Text='<%#Bind("LastName") %>' /><br />
              <asp:Label runat="server" ID="EmailLabel" 
                AssociatedControlID="EmailTextBox" Text="Email" />
              <asp:TextBox ID="EmailTextBox" runat="server" 
                Text='<%#Bind("EmailAddress") %>' />
            </td>
            <td>
              <asp:LinkButton ID="InsertButton" runat="server" 
                CommandName="Insert" Text="Insert" />
            </td>
          </tr>
        </InsertItemTemplate>
      </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"
        InsertCommand="INSERT INTO Person.Contact
          ([FirstName], [LastName], [EmailAddress], [PasswordHash], [PasswordSalt]) 
          Values(@FirstName, @LastName, @EmailAddress, '', '');
          SELECT @ContactID = SCOPE_IDENTITY()">
        <InsertParameters>
          <asp:Parameter Name="FirstName" />
          <asp:Parameter Name="LastName" />
          <asp:Parameter Name="EmailAddress" />
          <asp:Parameter Name="ContactID" Type="Int32" Direction="Output" />
        </InsertParameters>
      </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">

  '<Snippet3>
  Sub ContactsListView_ItemInserted(ByVal sender As Object, ByVal e As ListViewInsertedEventArgs)

    If e.Exception IsNot Nothing Then

      If e.AffectedRows = 0 Then
        e.KeepInInsertMode = True
        Message.Text = "An exception occurred inserting the new Contact. " & _
          "Please verify your values and try again."
      Else
        Message.Text = "An exception occurred inserting the new Contact. " & _
          "Please verify the values in the newly inserted item."
      End If

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

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    Message.Text = ""
  End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>ListView.ItemInserted Example</title>
  </head>
  <body>
    <form id="form1" runat="server">
        
      <h3>ListViewItemInserted Example</h3>
            
      <asp:Label ID="Message"
        ForeColor="Red"          
        runat="server"/>
      <br/>
      
      <asp:ListView ID="ContactsListView" 
        DataSourceID="ContactsDataSource" 
        DataKeyNames="ContactID"
        OnItemInserted="ContactsListView_ItemInserted"  
        InsertItemPosition="LastItem"
        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>&nbsp;
              <asp:Label ID="EmailLabel" runat="server" Text='<%#Eval("EmailAddress") %>' />
            </td>
          </tr>
        </ItemTemplate>
        <InsertItemTemplate>
          <tr style="background-color:#D3D3D3">
            <td valign="top">
              <asp:Label runat="server" ID="FirstNameLabel" 
                AssociatedControlID="FirstNameTextBox" Text="First Name"/>
              <asp:TextBox ID="FirstNameTextBox" runat="server" 
                Text='<%#Bind("FirstName") %>' /><br />
              <asp:Label runat="server" ID="LastNameLabel" 
                AssociatedControlID="LastNameTextBox" Text="Last Name" />
              <asp:TextBox ID="LastNameTextBox" runat="server" 
                Text='<%#Bind("LastName") %>' /><br />
              <asp:Label runat="server" ID="EmailLabel" 
                AssociatedControlID="EmailTextBox" Text="Email" />
              <asp:TextBox ID="EmailTextBox" runat="server" 
                Text='<%#Bind("EmailAddress") %>' />
            </td>
            <td>
              <asp:LinkButton ID="InsertButton" runat="server" 
                CommandName="Insert" Text="Insert" />
            </td>
          </tr>
        </InsertItemTemplate>
      </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"
        InsertCommand="INSERT INTO Person.Contact
          ([FirstName], [LastName], [EmailAddress], [PasswordHash], [PasswordSalt]) 
          Values(@FirstName, @LastName, @EmailAddress, '', '');
          SELECT @ContactID = SCOPE_IDENTITY()">
        <InsertParameters>
          <asp:Parameter Name="FirstName" />
          <asp:Parameter Name="LastName" />
          <asp:Parameter Name="EmailAddress" />
          <asp:Parameter Name="ContactID" Type="Int32" Direction="Output" />
        </InsertParameters>
      </asp:SqlDataSource>
      
    </form>
  </body>
</html>

설명

ListView 를 발생 시킵니다를 ItemInserted 이벤트에 있는 삽입 단추를 InsertItemTemplate 템플릿을 클릭 하면 후는 ListView 컨트롤이 데이터 소스에서 레코드를 업데이트 합니다. (삽입 단추는 단추입니다 CommandName 속성을 "Insert"로 설정 합니다.) ItemInserted 이벤트 삽입된 된 항목에 대 한 데이터베이스에서 자동으로 생성 된 값을 검색 하는 등 사용자 지정 작업을 수행할 수 있습니다.

ListViewInsertedEventArgs 개체 삽입 된 항목 및 발생 한 예외 수를 결정 하는 이벤트 처리 메서드에 전달 됩니다. 삽입 작업의 영향을 받는 항목의 수를 확인 하려면 사용 된 AffectedRows 속성입니다. 사용 된 Exception 예외가 발생 했는지 여부를 결정 하는 속성입니다. 설정 하 여 이벤트 처리 메서드에서 예외가 처리 되었는지 여부를 나타낼 수도 있습니다는 ExceptionHandled 속성입니다. 사용 하 여 데이터 원본에 전송 된 삽입된 된 항목의 필드 값에 액세스 하는 경우는 Values 속성입니다.

기본적으로 ListView 지웁니다 제어는 InsertItemTemplate 사용자가 삽입 될 새 항목에 대 한 값을 추가할 수 있도록 하는 삽입 작업 후 템플릿. 삽입 작업 중에 예외가 발생 하는 경우 유지할 수 있습니다 합니다 ListView 컨트롤을 설정 하 여 삽입 모드로 합니다 KeepInInsertMode 속성을 true입니다. 이 다시 바인딩 횟수는 InsertItemTemplate 값에 항목을 삽입 하려는 이전 시도가 템플릿에서 합니다.

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

생성자

ListViewInsertedEventArgs(Int32, Exception)

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

속성

AffectedRows

삽입 작업이 적용되는 행의 수를 가져옵니다.

Exception

삽입 작업을 진행하는 동안 발생한 예외가 있는 경우 이 예외를 가져옵니다.

ExceptionHandled

삽입 작업 과정에서 발생한 예외를 이벤트 처리기에서 처리했는지 여부를 나타내는 값을 가져오거나 설정합니다.

KeepInInsertMode

사용자의 입력 값이 InsertItemTemplate 템플릿 내에 있는 컨트롤에 대해 유지되는지 여부를 나타내는 값을 가져오거나 설정합니다.

Values

삽입된 레코드에 대한 필드 이름/값 쌍을 가져옵니다.

메서드

Equals(Object)

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

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

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

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

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

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

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

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

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

(다음에서 상속됨 Object)

적용 대상

추가 정보