Skip to content

DevExpress-Examples/asp-net-web-forms-grid-create-edit-form-template-dynamically

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grid View for ASP.NET Web Forms - How to create edit form templates dynamically

This example demonstrates how to implement the ITemplate interface to create an edit form template dynamically.

Edit form template

Overview

Follow the steps below to create an edit form template dynamically:

  1. 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;
        // ...
        }
    }
  2. 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);
    }
  3. In the Page_Load event handler, assign the new template to the grid's EditForm propety.

    protected void Page_Load(object sender, EventArgs e){
        ASPxGridView1.Templates.EditForm = template;
        template.Grid = ASPxGridView1;
    }
  4. 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;
        // ...
    }

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Implement the ITemplate interface to create an edit form template dynamically.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •