Giter Site home page Giter Site logo

devexpress-examples / how-to-create-edit-form-templates-dynamically-e986 Goto Github PK

View Code? Open in Web Editor NEW
0.0 54.0 1.0 404 KB

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

License: Other

C# 28.72% ASP.NET 42.75% Visual Basic .NET 28.53%
dotnet gridview templates web-forms template-replacement

how-to-create-edit-form-templates-dynamically-e986's Introduction

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

how-to-create-edit-form-templates-dynamically-e986's People

Contributors

devexpressexamplebot avatar elenapeskova avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

elenapeskova

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.