FormViewInsertedEventArgs.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 EmployeeFormView_ItemInserted(Object sender, FormViewInsertedEventArgs e)
{
// Iterate through the Values collection and display the
// values.
MessageLabel.Text = "The Values collection contains " +
"the following key/value pairs:<br/><br/>";
foreach (DictionaryEntry entry in e.Values)
{
MessageLabel.Text += "Key=" + entry.Key.ToString() + ", " +
"Value=" + entry.Value.ToString() + "<br/>";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>FormViewInsertedEventArgs Values Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>FormViewInsertedEventArgs Values Example</h3>
<asp:formview id="EmployeeFormView"
datasourceid="EmployeeSource"
allowpaging="true"
datakeynames="EmployeeID"
emptydatatext="No employees found."
oniteminserted="EmployeeFormView_ItemInserted"
runat="server">
<itemtemplate>
<table>
<tr>
<td rowspan="5">
<asp:image id="CompanyLogoImage"
imageurl="~/Images/Logo.jpg"
alternatetext="Company logo"
runat="server"/>
</td>
<td colspan="2">
</td>
</tr>
<tr>
<td>
<b>Name:</b>
</td>
<td>
<%# Eval("FirstName") %> <%# Eval("LastName") %>
</td>
</tr>
<tr>
<td>
<b>Title:</b>
</td>
<td>
<%# Eval("Title") %>
</td>
</tr>
<tr>
<td colspan="2">
<asp:linkbutton id="NewButton"
text="New"
commandname="New"
runat="server"/>
</td>
</tr>
</table>
</itemtemplate>
<insertitemtemplate>
<table>
<tr>
<td rowspan="4">
<asp:image id="CompanyLogoEditImage"
imageurl="~/Images/Logo.jpg"
alternatetext="Company logo"
runat="server"/>
</td>
<td colspan="2">
</td>
</tr>
<tr>
<td>
<b><asp:Label
runat="server"
AssociatedControlID="FirstNameInsertTextBox"
Text="Name" />:</b>
</td>
<td>
<asp:textbox id="FirstNameInsertTextBox"
text='<%# Bind("FirstName") %>'
runat="server"/>
<asp:textbox id="LastNameInsertTextBox"
text='<%# Bind("LastName") %>'
runat="server"/>
</td>
</tr>
<tr>
<td>
<b><asp:Label
runat="server"
AssociatedControlID="TitleInsertTextBox"
Text="Title" />:</b>
</td>
<td>
<asp:textbox id="TitleInsertTextBox"
text='<%# Bind("Title") %>'
runat="server"/>
</td>
</tr>
<tr>
<td colspan="2">
<asp:linkbutton id="InsertButton"
text="Insert"
commandname="Insert"
runat="server"/>
<asp:linkbutton id="CancelButton"
text="Cancel"
commandname="Cancel"
runat="server"/>
</td>
</tr>
</table>
</insertitemtemplate>
</asp:formview>
<br/><br/>
<asp:label id="MessageLabel"
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="EmployeeSource"
selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [PhotoPath] From [Employees]"
insertcommand="Insert Into [Employees] ([LastName], [FirstName], [Title]) VALUES (@LastName, @FirstName, @Title)"
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 EmployeeFormView_ItemInserted(ByVal sender As Object, ByVal e As FormViewInsertedEventArgs)
' Iterate through the Values collection and display the
' values.
MessageLabel.Text = "The Values collection contains " & _
"the following key/value pairs:<br/><br/>"
' In Visual Basic, the DictionaryItem objects contained in the
' Values collection must be copied to an array before
' you can iterate through the collection.
Dim itemArray(e.Values.Count - 1) As DictionaryEntry
e.Values.CopyTo(itemArray, 0)
Dim entry As DictionaryEntry
For Each entry In itemArray
MessageLabel.Text &= "Key=" & entry.Key.ToString() & ", " & _
"Value=" & entry.Value.ToString() & "<br/>"
Next
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>FormViewInsertedEventArgs Values Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>FormViewInsertedEventArgs Values Example</h3>
<asp:formview id="EmployeeFormView"
datasourceid="EmployeeSource"
allowpaging="true"
datakeynames="EmployeeID"
emptydatatext="No employees found."
oniteminserted="EmployeeFormView_ItemInserted"
runat="server">
<itemtemplate>
<table>
<tr>
<td rowspan="5">
<asp:image id="CompanyLogoImage"
imageurl="~/Images/Logo.jpg"
alternatetext="Company logo"
runat="server"/>
</td>
<td colspan="2">
</td>
</tr>
<tr>
<td>
<b>Name:</b>
</td>
<td>
<%# Eval("FirstName") %> <%# Eval("LastName") %>
</td>
</tr>
<tr>
<td>
<b>Title:</b>
</td>
<td>
<%# Eval("Title") %>
</td>
</tr>
<tr>
<td colspan="2">
<asp:linkbutton id="NewButton"
text="New"
commandname="New"
runat="server"/>
</td>
</tr>
</table>
</itemtemplate>
<insertitemtemplate>
<table>
<tr>
<td rowspan="4">
<asp:image id="CompanyLogoEditImage"
imageurl="~/Images/Logo.jpg"
alternatetext="Company logo"
runat="server"/>
</td>
<td colspan="2">
</td>
</tr>
<tr>
<td>
<b><asp:Label runat="server"
AssociatedControlID="FirstNameInsertTextBox"
Text="Name" />:</b>
</td>
<td>
<asp:textbox id="FirstNameInsertTextBox"
text='<%# Bind("FirstName") %>'
runat="server"/>
<asp:textbox id="LastNameInsertTextBox"
text='<%# Bind("LastName") %>'
runat="server"/>
</td>
</tr>
<tr>
<td>
<b><asp:Label runat="server"
AssociatedControlID="TitleInsertTextBox"
Text="Title" />:</b>
</td>
<td>
<asp:textbox id="TitleInsertTextBox"
text='<%# Bind("Title") %>'
runat="server"/>
</td>
</tr>
<tr>
<td colspan="2">
<asp:linkbutton id="InsertButton"
text="Insert"
commandname="Insert"
runat="server"/>
<asp:linkbutton id="CancelButton"
text="Cancel"
commandname="Cancel"
runat="server"/>
</td>
</tr>
</table>
</insertitemtemplate>
</asp:formview>
<br/><br/>
<asp:label id="MessageLabel"
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="EmployeeSource"
selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [PhotoPath] From [Employees]"
insertcommand="Insert Into [Employees] ([LastName], [FirstName], [Title]) VALUES (@LastName, @FirstName, @Title)"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
</form>
</body>
</html>
注解
使用 Values 属性访问插入记录的字段的值。 例如,可以使用这些值来保留插入记录的日志。
该 Values 属性返回 OrderedDictionary 实现 System.Collections.Specialized.IOrderedDictionary 接口的对象。 该 OrderedDictionary 对象包含表示 System.Collections.DictionaryEntry 插入记录的字段的对象。 若要访问字段名称,请使用 Keys 对象的属性 OrderedDictionary 。 同样,可以使用属性访问字段值 Values 。
备注
作为快捷方式,还可以使用对象的索引器 OrderedDictionary 直接访问字段值。 使用索引器的优点是它直接返回字段值。 依赖于字段顺序 ((如 AccessDataSource) )的数据源控件只能按索引访问字段值。