Hinweis: Diese Eigenschaft ist neu in .NET Framework, Version 2.0.
Ruft die Vorlage ab, mit der ein Element im Bearbeitungsmodus in einem
TemplateField-Objekt angezeigt wird, oder legt diese Vorlage fest.
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)
Visual Basic (Deklaration)
<TemplateContainerAttribute(GetType(IDataItemContainer), BindingDirection.TwoWay)> _
Public Overridable Property EditItemTemplate As ITemplate
Visual Basic (Verwendung)
Dim instance As TemplateField
Dim value As ITemplate
value = instance.EditItemTemplate
instance.EditItemTemplate = value
[TemplateContainerAttribute(typeof(IDataItemContainer), BindingDirection.TwoWay)]
public virtual ITemplate EditItemTemplate { get; set; }
[TemplateContainerAttribute(typeof(IDataItemContainer), BindingDirection::TwoWay)]
public:
virtual property ITemplate^ EditItemTemplate {
ITemplate^ get ();
void set (ITemplate^ value);
}
/** @property */
public ITemplate get_EditItemTemplate ()
/** @property */
public void set_EditItemTemplate (ITemplate value)
public function get EditItemTemplate () : ITemplate
public function set EditItemTemplate (value : ITemplate)
Eigenschaftenwert
Ein in System.Web.UI.ITemplate implementiertes Objekt, das die Vorlage zum Anzeigen eines Elements im Bearbeitungsmodus in TemplateField enthält. Der Standardwert ist NULL (Nothing in Visual Basic) und gibt an, dass diese Eigenschaft nicht festgelegt ist.
Geben Sie mithilfe der EditItemTemplate-Eigenschaft den benutzerdefinierten Inhalt an, der für ein Element im Bearbeitungsmodus in einem TemplateField-Objekt angezeigt wird. Definieren Sie den Inhalt, indem Sie eine Vorlage erstellen, die angibt, wie ein Element im Bearbeitungsmodus wiedergegeben wird. Die EditItemTemplate-Eigenschaft enthält i. d. R. Eingabesteuerelemente, damit der Benutzer einen Wert in einer Datenquelle ändern kann.
Platzieren Sie zum Angeben einer Vorlage zunächst öffnende und schließende <EditItemTemplate>-Tags zwischen den Anfangs- und Endtags des <TemplateField>-Elements. Anschließend fügen Sie den benutzerdefinierten Inhalt zwischen den Anfangs- und End-<EditItemTemplate>-Tags hinzu. Bei dem Inhalt kann es sich um einfachen Text handeln, er kann aber auch in komplexerer Form vorliegen (beispielsweise, wenn weitere Steuerelemente in die Vorlage eingebettet werden).
Bestimmen Sie zunächst, welches TableCell-Objekt im datengebundenen Steuerelement das Steuerelement enthält, um programmgesteuert auf ein in einer Vorlage definiertes Steuerelement zuzugreifen. Greifen Sie anschließend mithilfe der Controls-Auflistung des TableCell-Objekts auf das Steuerelement zu. Sie können auch die FindControl-Methode des TableCell-Objekts zum Suchen des Steuerelements verwenden, wenn das Steuerelement über eine ID verfügt.
Im folgenden Codebeispiel wird veranschaulicht, wie mit der EditItemTemplate-Eigenschaft eine benutzerdefinierte Vorlage für ein Element im Bearbeitungsmodus in einer TemplateField-Feldspalte eines GridView-Steuerelements erstellt wird. Die Vorlage enthält Serversteuerelemente für die Validierung, mit denen verhindert wird, dass ein Wertfeld nicht vom Benutzer gefüllt wird.
<%@ Page language="VB" %>
<script runat="server">
Sub AuthorsGridView_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
' The GridView control does not automatically extract updated values
' from TemplateField column fields. These values must be added manually
' to the NewValues dictionary.
' Get the GridViewRow object that represents the row being edited
' from the Rows collection of the GridView control.
Dim index As Integer = AuthorsGridView.EditIndex
Dim row As GridViewRow = AuthorsGridView.Rows(index)
' Get the controls that contain the updated values. In this
' example, the updated values are contained in the TextBox
' controls declared in the edit item templates of each TemplateField
' column fields in the GridView control.
Dim lastName As TextBox = CType(row.FindControl("LastNameTextBox"), TextBox)
Dim firstName As TextBox = CType(row.FindControl("FirstNameTextBox"), TextBox)
' Add the updated values to the NewValues dictionary. Use the
' parameter names declared in the parameterized update query
' string for the key names.
e.NewValues("au_lname") = lastName.Text
e.NewValues("au_fname") = firstName.Text
End Sub
</script>
<html>
<body>
<form id="Form1" runat="server">
<h3>TemplateField EditItemTemplate Example</h3>
<!-- The GridView control automatically sets the columns -->
<!-- specified in the datakeynames attribute as read-only. -->
<!-- No input controls are rendered for these columns in -->
<!-- edit mode. -->
<asp:gridview id="AuthorsGridView"
datasourceid="AuthorsSqlDataSource"
autogeneratecolumns="false"
autogenerateeditbutton="true"
datakeynames="au_id"
cellpadding="10"
onrowupdating="AuthorsGridView_RowUpdating"
runat="server">
<columns>
<asp:boundfield datafield="au_id"
headertext="Author ID"
readonly="true"/>
<asp:templatefield headertext="Last Name"
itemstyle-verticalalign="Top">
<itemtemplate>
<%#Eval("au_lname")%>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="LastNameTextBox"
text='<%#Eval("au_lname")%>'
width="90"
runat="server"/>
<br/>
<asp:requiredfieldvalidator id="LastNameRequiredValidator"
controltovalidate="LastNameTextBox"
display="Dynamic"
text="Please enter a last name."
runat="server" />
</edititemtemplate>
</asp:templatefield>
<asp:templatefield headertext="First Name"
itemstyle-verticalalign="Top">
<itemtemplate>
<%#Eval("au_fname")%>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="FirstNameTextBox"
text='<%#Eval("au_fname")%>'
width="90"
runat="server"/>
<br/>
<asp:requiredfieldvalidator id="FirstNameRequiredValidator"
controltovalidate="FirstNameTextBox"
display="Dynamic"
text="Please enter a first name."
runat="server" />
</edititemtemplate>
</asp:templatefield>
<asp:checkboxfield datafield="contract"
headertext="Contract"
readonly="true"/>
</columns>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Pubs sample database. -->
<asp:sqldatasource id="AuthorsSqlDataSource"
selectcommand="SELECT [au_id], [au_lname], [au_fname], [contract] FROM [authors]"
updatecommand="UPDATE authors SET au_lname=@au_lname, au_fname=@au_fname WHERE (authors.au_id = @au_id)"
connectionstring="server=localhost;database=pubs;integrated security=SSPI"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
<%@ Page language="C#" %>
<script runat="server">
void AuthorsGridView_RowUpdating (Object sender, GridViewUpdateEventArgs e)
{
// The GridView control does not automatically extract updated values
// from TemplateField column fields. These values must be added manually
// to the NewValues dictionary.
// Get the GridViewRow object that represents the row being edited
// from the Rows collection of the GridView control.
int index = AuthorsGridView.EditIndex;
GridViewRow row = AuthorsGridView.Rows[index];
// Get the controls that contain the updated values. In this
// example, the updated values are contained in the TextBox
// controls declared in the edit item templates of each TemplateField
// column fields in the GridView control.
TextBox lastName = (TextBox)row.FindControl("LastNameTextBox");
TextBox firstName = (TextBox)row.FindControl("FirstNameTextBox");
// Add the updated values to the NewValues dictionary. Use the
// parameter names declared in the parameterized update query
// string for the key names.
e.NewValues["au_lname"] = lastName.Text;
e.NewValues["au_fname"] = firstName.Text;
}
</script>
<html>
<body>
<form runat="server">
<h3>TemplateField EditItemTemplate Example</h3>
<!-- The GridView control automatically sets the columns -->
<!-- specified in the datakeynames attribute as read-only. -->
<!-- No input controls are rendered for these columns in -->
<!-- edit mode. -->
<asp:gridview id="AuthorsGridView"
datasourceid="AuthorsSqlDataSource"
autogeneratecolumns="false"
autogenerateeditbutton="true"
datakeynames="au_id"
cellpadding="10"
onrowupdating="AuthorsGridView_RowUpdating"
runat="server">
<columns>
<asp:boundfield datafield="au_id"
headertext="Author ID"
readonly="true"/>
<asp:templatefield headertext="Last Name"
itemstyle-verticalalign="Top">
<itemtemplate>
<%#Eval("au_lname")%>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="LastNameTextBox"
text='<%#Eval("au_lname")%>'
width="90"
runat="server"/>
<br/>
<asp:requiredfieldvalidator id="LastNameRequiredValidator"
controltovalidate="LastNameTextBox"
display="Dynamic"
text="Please enter a last name."
runat="server" />
</edititemtemplate>
</asp:templatefield>
<asp:templatefield headertext="First Name"
itemstyle-verticalalign="Top">
<itemtemplate>
<%#Eval("au_fname")%>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="FirstNameTextBox"
text='<%#Eval("au_fname")%>'
width="90"
runat="server"/>
<br/>
<asp:requiredfieldvalidator id="FirstNameRequiredValidator"
controltovalidate="FirstNameTextBox"
display="Dynamic"
text="Please enter a first name."
runat="server" />
</edititemtemplate>
</asp:templatefield>
<asp:checkboxfield datafield="contract"
headertext="Contract"
readonly="true"/>
</columns>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Pubs sample database. -->
<asp:sqldatasource id="AuthorsSqlDataSource"
selectcommand="SELECT [au_id], [au_lname], [au_fname], [contract] FROM [authors]"
updatecommand="UPDATE authors SET au_lname=@au_lname, au_fname=@au_fname WHERE (authors.au_id = @au_id)"
connectionstring="server=localhost;database=pubs;integrated security=SSPI"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
.NET Framework
Unterstützt in: 2.0