FormViewInsertEventArgs Třída
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Poskytuje data pro událost ItemInserting.
public ref class FormViewInsertEventArgs : System::ComponentModel::CancelEventArgs
public class FormViewInsertEventArgs : System.ComponentModel.CancelEventArgs
type FormViewInsertEventArgs = class
inherit CancelEventArgs
Public Class FormViewInsertEventArgs
Inherits CancelEventArgs
- Dědičnost
Příklady
Následující příklad ukazuje, jak použít FormViewInsertEventArgs objekt předaný metodě zpracování událostí pro ItemInserting událost zrušit operaci vložení, když uživatel opustí pole prázdné.
Důležité
Tento příklad obsahuje textové pole, které přijímá vstup uživatele, což je potenciální bezpečnostní hrozba. Ve výchozím nastavení ASP.NET webové stránky ověřují, že vstup uživatele neobsahuje skripty ani elementy HTML. Další informace naleznete v tématu Přehled zneužití skriptů.
<%@ 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_ItemInserting(Object sender, FormViewInsertEventArgs e)
{
MessageLabel.Text = "";
// Iterate through the items in the Values collection
// and verify that the user entered a value for each
// text box displayed in the insert item template. Cancel
// the insert operation if the user left a text box empty.
foreach (DictionaryEntry entry in e.Values)
{
if (entry.Value.Equals(""))
{
// Use the Cancel property to cancel the
// insert operation.
e.Cancel = true;
MessageLabel.Text += "Please enter a value for the " +
entry.Key.ToString() + " field.<br/>";
}
}
}
void EmployeeFormView_ModeChanged(Object sender, EventArgs e)
{
// Clear the MessageLabel Label control when the FormView
// control changes modes.
MessageLabel.Text = "";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>FormViewInsertEventArgs Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>FormViewInsertEventArgs Example</h3>
<asp:formview id="EmployeeFormView"
datasourceid="EmployeeSource"
allowpaging="true"
datakeynames="EmployeeID"
emptydatatext="No employees found."
oniteminserting="EmployeeFormView_ItemInserting"
onmodechanged="EmployeeFormView_ModeChanged"
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_ItemInserting(ByVal sender As Object, ByVal e As FormViewInsertEventArgs)
MessageLabel.Text = ""
' Iterate through the items in the Values collection
' and verify that the user entered a value for each
' text box displayed in the insert item template. Cancel
' the insert operation if the user left a text box empty.
' 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
If entry.Value.Equals("") Then
' Use the Cancel property to cancel the
' insert operation.
e.Cancel = True
MessageLabel.Text &= "Please enter a value for the " & _
entry.Key.ToString() & " field.<br/>"
End If
Next
End Sub
Sub EmployeeFormView_ModeChanged(ByVal sender As Object, ByVal e As EventArgs)
' Clear the MessageLabel Label control when the FormView
' control changes modes.
MessageLabel.Text = ""
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>FormViewInsertEventArgs Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>FormViewInsertEventArgs Example</h3>
<asp:formview id="EmployeeFormView"
datasourceid="EmployeeSource"
allowpaging="true"
datakeynames="EmployeeID"
emptydatatext="No employees found."
oniteminserting="EmployeeFormView_ItemInserting"
onmodechanged="EmployeeFormView_ModeChanged"
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>
Poznámky
Ovládací FormView prvek vyvolá ItemInserting událost, když se v ovládacím prvku klikne na tlačítko Vložit (tlačítko s CommandName vlastností nastavenou na Vložit), ale před vložením FormView záznamu ovládací prvek. To vám umožní poskytnout metodu zpracování událostí, která provádí vlastní rutinu, například kódování HTML nebo ověřování hodnot záznamu před vložením do zdroje dat, kdykoli dojde k této události.
FormViewInsertEventArgs Objekt se předává metodě zpracování událostí, která umožňuje určit hodnotu volitelného argumentu příkazu odeslaného FormView do ovládacího prvku a označit, že operace vložení by měla být zrušena. K určení hodnoty argumentu příkazu použijte CommandArgument vlastnost. Chcete-li operaci vložení zrušit, nastavte Cancel vlastnost na truehodnotu . Hodnoty polí nového záznamu můžete také číst nebo upravovat pomocí Values vlastnosti.
Další informace o zpracování událostí naleznete v tématu Zpracování a vyvolávání událostí.
Seznam počátečních hodnot vlastností pro instanci FormViewInsertEventArgs třídy naleznete v konstruktoru FormViewInsertEventArgs .
Konstruktory
| Name | Description |
|---|---|
| FormViewInsertEventArgs(Object) |
Inicializuje novou instanci FormViewInsertEventArgs třídy. |
Vlastnosti
| Name | Description |
|---|---|
| Cancel |
Získá nebo nastaví hodnotu určující, zda má být událost zrušena. (Zděděno od CancelEventArgs) |
| CommandArgument |
Získá argument příkazu pro operaci vložení předaný ovládacímu FormView prvku. |
| Values |
Získá slovník, který obsahuje páry název pole/hodnota záznamu vložit. |
Metody
| Name | Description |
|---|---|
| Equals(Object) |
Určuje, zda je zadaný objekt roven aktuálnímu objektu. (Zděděno od Object) |
| GetHashCode() |
Slouží jako výchozí funkce hash. (Zděděno od Object) |
| GetType() |
Získá Type aktuální instance. (Zděděno od Object) |
| MemberwiseClone() |
Vytvoří mělkou kopii aktuálního Object. (Zděděno od Object) |
| ToString() |
Vrátí řetězec, který představuje aktuální objekt. (Zděděno od Object) |