DetailsViewDeletedEventArgs.Values 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取包含要删除的项的非键字段名称/值对的字典。
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。
示例
下面的代码示例演示如何使用 Values 属性访问已删除记录的非键字段的值。
<%@ 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 StoresDetailView_ItemDeleted(Object sender,
DetailsViewDeletedEventArgs 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>DetailsViewDeletedEventArgs Keys and Values Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>DetailsViewDeletedEventArgs Keys and Values Example</h3>
<asp:detailsview id="CustomerDetailsView"
datasourceid="DetailsViewSource"
datakeynames="CustomerID"
autogeneratedeletebutton="true"
autogeneraterows="true"
allowpaging="true"
onitemdeleted="StoresDetailView_ItemDeleted"
runat="server">
<fieldheaderstyle backcolor="Navy"
forecolor="White"/>
</asp:detailsview>
<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="DetailsViewSource"
selectcommand="Select [CustomerID], [CompanyName], [Address],
[City], [PostalCode], [Country] From [Customers]"
deletecommand="Delete [Customers]
Where [CustomerID]=@CustomerID"
connectionstring=
"<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
</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 StoresDetailView_ItemDeleted(ByVal sender As Object, _
ByVal e As DetailsViewDeletedEventArgs)
Dim entry As DictionaryEntry
Dim i As Integer
' 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>DetailsViewDeletedEventArgs Keys and Values Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>DetailsViewDeletedEventArgs Keys and Values Example</h3>
<asp:detailsview id="CustomerDetailsView"
datasourceid="DetailsViewSource"
datakeynames="CustomerID"
autogeneratedeletebutton="true"
autogeneraterows="true"
allowpaging="true"
onitemdeleted="StoresDetailView_ItemDeleted"
runat="server">
<fieldheaderstyle backcolor="Navy"
forecolor="White"/>
</asp:detailsview>
<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="DetailsViewSource"
selectcommand="Select [CustomerID], [CompanyName], [Address],
[City], [PostalCode], [Country] From [Customers]"
deletecommand="Delete [Customers]
Where [CustomerID]=@CustomerID"
connectionstring=
"<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
</form>
</body>
</html>
注解
Values使用 属性访问要删除的记录的非键字段的值。 例如,可以使用这些值来保留已删除记录的日志。
注意
此属性不包含记录的键字段。 若要访问键字段,请使用 Keys 属性。
属性 Values 返回实现 IOrderedDictionary 接口的对象 IOrderedDictionary 。 对象包含 DictionaryEntry 表示要删除的记录的非键字段的对象。
注意
作为快捷方式,还可以使用 对象的索引器 IOrderedDictionary 直接访问字段值。