Tab

GridViewTemplates.EditForm Property

Gets or sets a template for displaying the edit form.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v20.2.dll

Declaration

[DefaultValue(null)]
public virtual ITemplate EditForm { get; set; }

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:

veEditForm

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.

Examples

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;
    }
}
See Also