This example demonstrates how to implement the ITemplate interface to create an edit form template dynamically.
Follow the steps below to create an edit form template dynamically:
-
Use the ITemplate interface to create an edit form template and call the InstantiateIn method to populate the template with editors.
public class EdiFormTemplate:ITemplate{ private ASPxGridView _gridView; public ASPxGridView Grid { get { return _gridView; } set { _gridView = value; } } public EdiFormTemplate(){ } public void InstantiateIn(Control container){ int index = (container as GridViewEditFormTemplateContainer).VisibleIndex; // ... } }
-
To add Update and Cancel command buttons to the edit form, create a template replacement - add a GridViewTemplateReplacement object and specify its ReplacementType property.
public void InstantiateIn(Control container){ // ... ASPxGridViewTemplateReplacement upd = new ASPxGridViewTemplateReplacement(); upd.ReplacementType = GridViewTemplateReplacementType.EditFormUpdateButton; upd.ID = "Update"; container.Controls.Add(upd); ASPxGridViewTemplateReplacement can = new ASPxGridViewTemplateReplacement(); can.ReplacementType = GridViewTemplateReplacementType.EditFormCancelButton; can.ID = "Cancel"; container.Controls.Add(can); }
-
In the
Page_Load
event handler, assign the new template to the grid'sEditForm
propety.protected void Page_Load(object sender, EventArgs e){ ASPxGridView1.Templates.EditForm = template; template.Grid = ASPxGridView1; }
-
To access an editor within the template, call the grid's server-side FindEditFormTemplateControl method.
protected void ASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e){ ASPxPageControl pg = ((ASPxGridView)sender).FindEditFormTemplateControl("ASPxPageControl1") as ASPxPageControl; // ... }
- EdiFormTemplate.cs (VB: EdiFormTemplate.vb)
- Default.aspx (VB: Default.aspx)
- Default.aspx.cs (VB: Default.aspx.vb)
(you will be redirected to DevExpress.com to submit your response)