GridViewDeleteEventArgs.Values 속성

정의

삭제할 행에 대한 키가 아닌 필드 이름/값 쌍의 사전을 가져옵니다.

public:
 property System::Collections::Specialized::IOrderedDictionary ^ Values { System::Collections::Specialized::IOrderedDictionary ^ get(); };
public System.Collections.Specialized.IOrderedDictionary Values { get; }
member this.Values : System.Collections.Specialized.IOrderedDictionary
Public ReadOnly Property Values As IOrderedDictionary

속성 값

IOrderedDictionary

삭제할 행에 대한 키가 아닌 필드의 이름/값 쌍이 들어 있는 IOrderedDictionary 개체입니다.

예제

다음 예제에서는 사용 하는 방법의 Values 삭제할 행에 대 한 키가 아닌 필드의 값을 가져올 속성입니다. 값은 다음 삭제 된 레코드의 로그 파일에 기록 됩니다.


<%@ Page language="C#" %>
<%@ import namespace="System.IO" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void CustomersGridView_RowDeleting(Object sender, GridViewDeleteEventArgs e)
  {

    // Record the delete operation in a log file.

    // Create the log text. 
    String logText = "";

    // Append the values of the key fields to the log text.
    foreach (DictionaryEntry keyEntry in e.Keys)
    {
      logText += keyEntry.Key + "=" + keyEntry.Value + ";";
    }

    // Append the values of the non-key fields to the log text.
    foreach (DictionaryEntry valueEntry in e.Values)
    {
      logText += valueEntry.Key + "=" + valueEntry.Value + ";";
    }

    // Display the log content.
    LogTextLabel.Text = logText;
    
    // Append the text to a log file.
    try
    {
      StreamWriter sw;
      sw = File.AppendText(Server.MapPath(null) + "\\deletelog.txt");
      sw.WriteLine(logText);
      sw.Flush();
      sw.Close();
    }
    catch(UnauthorizedAccessException ex)
    {
      // You must provide read/write access to the file using ACLs.
      LogErrorLabel.Text = "You do not have permission to write to the log.";
    }

  }
    
  void CustomersGridView_RowDeleted(Object sender, GridViewDeletedEventArgs e)
  {
    
    if (e.Exception == null)
    {
      // The delete operation succeeded. Clear the message label.
      Message.Text = "";
    }
    else
    {
      // The delete operation failed. Display an error message.
      Message.Text = e.AffectedRows.ToString() + " rows deleted. " + e.Exception.Message;
      e.ExceptionHandled = true;
    }
        
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridViewDeleteEventArgs Keys and Values Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridViewDeleteEventArgs Keys and Values Example</h3>
            
      <asp:label id="Message"
        forecolor="Red"          
        runat="server"/>
        
      <br/>
      
      <asp:label id="LogTextLabel"
        forecolor="Red"          
        runat="server"/>
        
      <br/>
        
      <asp:label id="LogErrorLabel"
        forecolor="Red"          
        runat="server"/>
                
      <br/>

      <asp:gridview id="CustomersGridView" 
        allowpaging="true"
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="true"
        autogeneratedeletebutton="true" 
        datakeynames="CustomerID"
        onrowdeleted="CustomersGridView_RowDeleted"
        onrowdeleting="CustomersGridView_RowDeleting"   
        runat="server">
        
      </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" %>
<%@ import namespace="System.IO" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Sub CustomersGridView_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs)

    ' Record the delete operation in a log file.

    ' Create the log text. 
    Dim logText As String = ""

    ' Append the values of the key fields to the log text.
    Dim i As Integer
    For i = 0 To e.Keys.Count - 1
    
      logText &= e.Keys(i).ToString() & ";"
      
    Next

    ' Append the values of the non-key fields to the log text.
    For i = 0 To e.Values.Count - 1
    
      If e.Values(i) IsNot Nothing Then
        logText &= e.Values(i).ToString() & ";"
      Else
        logText &= "Nothing" & ";"
      End If
      
    Next
    
    ' Display the log content.
    LogTextLabel.Text = logText

    ' Append the text to a log file.
    Try
    
      Dim sw As StreamWriter
      sw = File.AppendText(Server.MapPath(Nothing) & "\deletelog.txt")
      sw.WriteLine(logText)
      sw.Flush()
      sw.Close()
    
    Catch ex As UnauthorizedAccessException
    
      ' You must provide read/write access to the file using ACLs.
      LogErrorLabel.Text = "You do not have permission to write to the log."
    
    End Try

  End Sub
    
  Sub CustomersGridView_RowDeleted(ByVal sender As Object, ByVal e As GridViewDeletedEventArgs)
    
    If e.Exception Is Nothing Then
    
      ' The delete operation succeeded. Clear the message label.
      Message.Text = ""
    
    Else
    
      ' The delete operation failed. Display an error message.
      Message.Text = e.AffectedRows.ToString() & " rows deleted. " & e.Exception.Message
      e.ExceptionHandled = True
      
    End If
        
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridViewDeleteEventArgs Keys and Values Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridViewDeleteEventArgs Keys and Values Example</h3>
            
      <asp:label id="Message"
        forecolor="Red"          
        runat="server"/>
        
      <br/>
      
      <asp:label id="LogTextLabel"
        forecolor="Red"          
        runat="server"/>
        
      <br/>
        
      <asp:label id="LogErrorLabel"
        forecolor="Red"          
        runat="server"/>
                
      <br/>

      <asp:gridview id="CustomersGridView" 
        allowpaging="true"
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="true"
        autogeneratedeletebutton="true" 
        datakeynames="CustomerID"
        onrowdeleted="CustomersGridView_RowDeleted"
        onrowdeleting="CustomersGridView_RowDeleting"   
        runat="server">
        
      </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>

설명

Values 속성은 행에 대 한 키가 아닌 필드 이름/값 쌍을 자동으로 채워집니다. 항목의 필드 이름을 확인 하려면 사용 합니다 DictionaryEntry.Key 의 속성을 System.Collections.DictionaryEntry 개체를 Values 사전. 항목의 값을 확인 하려면 사용 된 DictionaryEntry.Value 속성입니다.

참고

기본 키 필드 또는 필드를이 사전에 포함 되지 않습니다. 기본 키 필드 또는 필드의 값에 액세스 하려면 사용 된 Keys 속성입니다.

적용 대상

추가 정보