DetailsViewInsertEventArgs 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 DetailsViewInsertEventArgs : System::ComponentModel::CancelEventArgs
public class DetailsViewInsertEventArgs : System.ComponentModel.CancelEventArgs
type DetailsViewInsertEventArgs = class
inherit CancelEventArgs
Public Class DetailsViewInsertEventArgs
Inherits CancelEventArgs
- Dědičnost
Příklady
Následující příklad kódu ukazuje, jak použít DetailsViewInsertEventArgs objekt předaný obslužné rutině ItemInserting události pro událost zrušit operaci vložení.
<%@ 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 CustomerDetailsView_ItemInserting(Object sender,
DetailsViewInsertEventArgs e)
{
// Use the Values property to retrieve the key field value.
String keyValue = e.Values["CustomerID"].ToString();
// Insert the record only if the key field is four characters
// long; otherwise, cancel the insert operation.
if (keyValue.Length == 4)
{
// Change the key field value to upper case before inserting
// the record in the data source.
e.Values["CustomerID"] = keyValue.ToUpper();
MessageLabel.Text = "";
}
else
{
MessageLabel.Text = "The key field must have four digits.";
e.Cancel = true;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>DetailsViewInsertEventArgs Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>DetailsViewInsertEventArgs Example</h3>
<asp:detailsview id="CustomerDetailsView"
datasourceid="DetailsViewSource"
datakeynames="CustomerID"
autogenerateinsertbutton="true"
autogeneraterows="true"
allowpaging="true"
oniteminserting="CustomerDetailsView_ItemInserting"
runat="server">
<fieldheaderstyle backcolor="Navy"
forecolor="White"/>
</asp:detailsview>
<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="DetailsViewSource"
selectcommand="Select [CustomerID], [CompanyName], [Address],
[City], [PostalCode], [Country] From [Customers]"
insertcommand="INSERT INTO [Customers]([CustomerID],
[CompanyName], [Address], [City], [PostalCode],
[Country]) VALUES (@CustomerID, @CompanyName, @Address,
@City, @PostalCode, @Country)"
connectionstring=
"<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
</form>
</body>
</html>
<%@ Page language="VB" autoeventwireup="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub CustomerDetailsView_ItemInserting(ByVal sender As Object, _
ByVal e As DetailsViewInsertEventArgs) _
Handles CustomerDetailsView.ItemInserting
' Use the Values property to retrieve the key field value.
Dim keyValue As String = e.Values("CustomerID").ToString()
' Insert the record only if the key field is four characters
' long; otherwise, cancel the insert operation.
If keyValue.Length = 4 Then
' Change the key field value to upper case before inserting
' the record in the data source.
e.Values("CustomerID") = keyValue.ToUpper()
MessageLabel.Text = ""
Else
MessageLabel.Text = "The key field must have four digits."
e.Cancel = True
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>DetailsViewInsertEventArgs Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>DetailsViewInsertEventArgs Example</h3>
<asp:detailsview id="CustomerDetailsView"
datasourceid="DetailsViewSource"
datakeynames="CustomerID"
autogenerateinsertbutton="true"
autogeneraterows="true"
allowpaging="true"
oniteminserting="CustomerDetailsView_ItemInserting"
runat="server">
<fieldheaderstyle backcolor="Navy"
forecolor="White"/>
</asp:detailsview>
<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="DetailsViewSource"
selectcommand="Select [CustomerID], [CompanyName], [Address],
[City], [PostalCode], [Country] From [Customers]"
insertcommand="INSERT INTO [Customers]([CustomerID],
[CompanyName], [Address], [City], [PostalCode],
[Country]) VALUES (@CustomerID, @CompanyName, @Address,
@City, @PostalCode, @Country)"
connectionstring=
"<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
</form>
</body>
</html>
Poznámky
Ovládací DetailsView 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 DetailsView záznamu ovládací prvek. To vám umožní poskytnout obslužnou rutinu události, která provádí vlastní rutinu, jako je například kódování HTML hodnoty záznamu před vložením do zdroje dat, kdykoli dojde k této události.
DetailsViewInsertEventArgs Objekt se předá obslužné rutině události, která umožňuje určit hodnotu volitelného argumentu příkazu odeslaného do DetailsView 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 DetailsViewInsertEventArgs třídy naleznete v konstruktoru DetailsViewInsertEventArgs .
Konstruktory
| Name | Description |
|---|---|
| DetailsViewInsertEventArgs(Object) |
Inicializuje novou instanci DetailsViewInsertEventArgs 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 DetailsView 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) |