GridViewDeletedEventArgs.Values Propriedade
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Obtém um dicionário de pares nome-valor do campo não chave para o registro excluído.
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
Valor da propriedade
Um IOrderedDictionary que contém um dicionário dos pares nome/valor do campo não chave para o registro excluído.
Exemplos
O exemplo a seguir demonstra como usar a Values propriedade para acessar os valores dos campos não chave para um registro excluído.
<%@ 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 CustomersGridView_RowDeleted(Object sender, GridViewDeletedEventArgs e)
{
// Display the value of the key fields in the Keys property.
KeysMessageLabel.Text =
"The key fields for the deleted record are: <br/>";
foreach (DictionaryEntry entry in e.Keys)
{
DisplayValue(entry, KeysMessageLabel);
}
// Display the value of the non-key fields in the Values
// property.
ValuesMessageLabel.Text =
"The non-key fields for the deleted record are: <br/>";
foreach (DictionaryEntry entry in e.Values)
{
DisplayValue(entry, ValuesMessageLabel);
}
}
void DisplayValue(DictionaryEntry entry, Label displayLabel)
{
// Display the field name contained in the DictionaryEntry object.
if (entry.Key != null)
{
displayLabel.Text += "Name=" + entry.Key.ToString() + ", ";
}
else
{
displayLabel.Text += "Name=null, ";
}
// Display the field value contained in the DictionaryEntry object.
if (entry.Value != null)
{
displayLabel.Text += "Value=" + entry.Value.ToString() + "<br/>";
}
else
{
displayLabel.Text += "Value=null<br/>";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridViewDeletedEventArgs Keys and Values Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridViewDeletedEventArgs Keys and Values Example</h3>
<asp:label id="Message"
forecolor="Red"
runat="server"/>
<br/>
<!-- The GridView control automatically sets the columns -->
<!-- specified in the datakeynames property as read-only. -->
<!-- No input controls are rendered for these columns in -->
<!-- edit mode. -->
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="true"
autogeneratedeletebutton="true"
allowpaging="true"
datakeynames="CustomerID"
onrowdeleted="CustomersGridView_RowDeleted"
runat="server">
</asp:gridview>
<br/>
<asp:label id="KeysMessageLabel"
forecolor="Red"
runat="server"/>
<br/><br/>
<asp:label id="ValuesMessageLabel"
forecolor="Red"
runat="server"/>
<!-- 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 CustomersGridView_RowDeleted(ByVal sender As Object, ByVal e As GridViewDeletedEventArgs)
Dim entry As DictionaryEntry
' Display the value of the key fields in the Keys property.
KeysMessageLabel.Text = _
"The key fields for the deleted record are: <br/>"
' In VB, you cannot iterate through the DictionaryEntry objects
' in the Keys property directly. Use the CopyTo method to
' copy the objects to an array first.
Dim keysArray(e.Keys.Count - 1) As DictionaryEntry
e.Keys.CopyTo(keysArray, 0)
' Iterate through the array and display its values.
For Each entry In keysArray
DisplayValue(entry, KeysMessageLabel)
Next
' Display the value of the non-key fields in the Values
' property.
ValuesMessageLabel.Text = _
"The non-key fields for the deleted record are: <br/>"
Dim valuesArray(e.Values.Count - 1) As DictionaryEntry
e.Values.CopyTo(valuesArray, 0)
For Each entry In valuesArray
DisplayValue(entry, ValuesMessageLabel)
Next
End Sub
Sub DisplayValue(ByVal entry As DictionaryEntry, ByVal displayLabel As Label)
' Display the field name contained in the DictionaryEntry object.
If entry.Key IsNot Nothing Then
displayLabel.Text &= "Name=" & entry.Key.ToString() & ", "
Else
displayLabel.Text &= "Name=null, "
End If
' Display the field value contained in the DictionaryEntry object.
If entry.Value IsNot Nothing Then
displayLabel.Text &= "Value=" & entry.Value.ToString() & "<br/>"
Else
displayLabel.Text &= "Value=null<br/>"
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridViewDeletedEventArgs Keys and Values Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridViewDeletedEventArgs Keys and Values Example</h3>
<asp:label id="Message"
forecolor="Red"
runat="server"/>
<br/>
<!-- The GridView control automatically sets the columns -->
<!-- specified in the datakeynames property as read-only. -->
<!-- No input controls are rendered for these columns in -->
<!-- edit mode. -->
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="true"
autogeneratedeletebutton="true"
allowpaging="true"
datakeynames="CustomerID"
onrowdeleted="CustomersGridView_RowDeleted"
runat="server">
</asp:gridview>
<br/>
<asp:label id="KeysMessageLabel"
forecolor="Red"
runat="server"/>
<br/><br/>
<asp:label id="ValuesMessageLabel"
forecolor="Red"
runat="server"/>
<!-- 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>
Comentários
Use a Values propriedade para acessar os valores dos campos não chave para um registro excluído. Por exemplo, você pode usar esses valores para manter um log de registros excluídos.
Observação
A Values propriedade é preenchida somente quando expressões de associação bidirecional são usadas no modelo de item. Para obter mais informações sobre expressões de associação bidirecional, consulte Associação a bancos de dados.
A propriedade de Values retorna um objeto que implementa a interface de System.Collections.Specialized.IOrderedDictionary. O objeto contém System.Collections.DictionaryEntry objetos que representam os campos não chave do registro excluído.
Observação
Essa propriedade não contém os campos de chave (conforme especificado pela DataKeyNames propriedade) para o registro excluído. Para acessar os campos de chave, use a Keys propriedade .