FormViewInsertedEventArgs.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 que contém os pares nome-valor do campo para o registro inserido.
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 objeto que contém um dicionário de pares de nome/valor do campo de chave para o registro inserido.
Exemplos
O exemplo a seguir demonstra como iterar por meio dos itens da Values coleção.
<%@ 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>
Comentários
Use a Values propriedade para acessar os valores dos campos para o registro inserido. Por exemplo, você pode usar esses valores para manter um log de registros inseridos.
A Values propriedade retorna um OrderedDictionary objeto que implementa a System.Collections.Specialized.IOrderedDictionary interface. O OrderedDictionary objeto contém System.Collections.DictionaryEntry objetos que representam os campos do registro inserido. Para acessar os nomes de campo, use a Keys propriedade do OrderedDictionary objeto. Da mesma forma, você pode acessar os valores de campo usando a Values propriedade.
Observação
Como atalho, você também pode usar o indexador do OrderedDictionary objeto para acessar os valores de campo diretamente. A vantagem em usar o indexador é que ele retorna valores de campo diretamente. Os controles de fonte de dados que dependem da ordem de campo (como AccessDataSource) podem acessar valores de campo apenas por índice.