System.Web.UI.WebControls Namespace TemplateField Class
.NET Framework version 2.0
Specifies the template to use for adding a row of data in a TemplateField control.
<asp:templatefield ... >
<insertitemtemplate>
... template definition here
</insertitemtemplate>
</asp:templatefield>
An ITemplate interface that defines how the TemplateField control is rendered when in insert mode.
The property is read/write with no default value.
Use the InsertItemTemplate to define the layout of elements in the TemplateField control when adding a row of data.
The InsertItemTemplate functions in the same way as the EditItemTemplate, but is rendered only when the parent control of the TemplateField is in insert mode.
To specify a template for adding a row of data, declare an <InsertItemTemplate> element between the opening and closing tags of the control. You can then list the contents of the template between the opening and closing <InsertItemTemplate> ... </InsertItemTemplate>
tags.
In the InsertItemTemplate, declare one or more input server controls ( TextBox, CheckBox, RadioButton, etc. ) and set their data-binding expressions to evaluate to a field in the parent control's data source.
To enable ItemTemplatethe built-in insert feature of the parent control, you must associate a field with an input control with a two-way binding expression, using the Bind method, as shown in the following example.
<asp:textbox maxlength=254 id = "msgSubject" runat = "server"
text=<%# Bind ( "MessageSubject" ) %> />
This allows the parent control to automatically display blank field values in the associated input control when in insert mode, and extract these values when the form is posted.
To perform the built-in insert operation, add a command button control to the template and set its CommandName property to "Insert", accordingly.
When the insert command button is clicked and the page is posted for processing, the TemplateField control automatically extracts the inserted field values from each associated input control and inserts the row of data in the underlying data source. For more information on two-way binding expressions, see DataBinding Expression Syntax.
To control the style of the insert row, use the InsertRowStyle property of the parent control.
The following example illustrates using the InsertItemTemplate to enable users to add a row of data.
Show me
TemplateField Members EditItemTemplate ItemTemplate