GridViewTemplates.EditForm Property
Gets or sets a template for displaying the edit form.
Namespace: DevExpress.Web
Assembly: DevExpress.Web.v19.1.dll
Declaration
Property Value
Type | Default | Description |
---|---|---|
ITemplate | *null* | An object that implements the ITemplate interface. |
Remarks
The image below shows the Edit Form’s default layout:
You can provide any possible layout for the Edit Form using the EditForm template. For an example, see the ASPxGridView’s Edit Form Template demo.
If you use edit form templates, you must process the update manually in the ASPxGridView.RowUpdating event handler.
Note
Once a template defined via the EditForm property is created within a grid control, it is instantiated within a container object of the GridViewEditFormTemplateContainer type. This container object exposes a set of specific properties to which the template’s child controls can be bound.
Example
This example demonstrates how to create the Edit Form‘s template at runtime.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DevExpress.Web.ASPxEditors;
using DevExpress.Web.ASPxGridView;
public partial class _Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
ASPxGridView1.Templates.EditForm = new EditFormTemplate();
}
protected void ASPxGridView1_RowUpdating(object sender,
DevExpress.Web.Data.ASPxDataUpdatingEventArgs e) {
e.NewValues["ProductName"] = (ASPxGridView1.FindEditFormTemplateControl("tbProductName")
as ASPxTextBox).Value;
e.NewValues["UnitPrice"] = (ASPxGridView1.FindEditFormTemplateControl("spinUnitPrice")
as ASPxSpinEdit).Value;
}
}
public class EditFormTemplate : ITemplate {
public void InstantiateIn(Control container) {
Table table = CreateHtmlTable();
container.Controls.Add(table);
ASPxTextBox tb = new ASPxTextBox();
tb.ID = "tbProductName";
tb.CssFilePath = @"~/App_Themes/Soft Orange/{0}/styles.css";
tb.CssPostfix = "Soft_Orange";
tb.Value = DataBinder.Eval((container as
GridViewEditFormTemplateContainer).DataItem, "ProductName");
table.Rows[0].Cells[0].Controls.Add(tb);
ASPxSpinEdit spin = new ASPxSpinEdit();
spin.ID = "spinUnitPrice";
spin.CssFilePath = @"~/App_Themes/Soft Orange/{0}/styles.css";
spin.CssPostfix = "Soft_Orange";
spin.Value = DataBinder.Eval((container as
GridViewEditFormTemplateContainer).DataItem, "UnitPrice");
table.Rows[0].Cells[1].Controls.Add(spin);
ASPxGridViewTemplateReplacement tr = new ASPxGridViewTemplateReplacement();
tr.ReplacementType = GridViewTemplateReplacementType.EditFormUpdateButton;
table.Rows[1].Cells[2].Controls.Add(tr);
Literal separator = new Literal();
separator.Text = " | ";
table.Rows[1].Cells[2].Controls.Add(separator);
tr = new ASPxGridViewTemplateReplacement();
tr.ReplacementType = GridViewTemplateReplacementType.EditFormCancelButton;
table.Rows[1].Cells[2].Controls.Add(tr);
}
Table CreateHtmlTable() {
Table table = new Table();
table.Rows.Add(new TableRow());
table.Rows[0].Cells.AddRange(new TableCell[] { new TableCell(),
new TableCell(),
new TableCell()});
table.Rows.Add(new TableRow());
table.Rows[1].Cells.AddRange(new TableCell[] { new TableCell(),
new TableCell(),
new TableCell()});
return table;
}
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the EditForm property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.