Skip to main content
A newer version of this page is available. .
Tab

ASPxGridViewTemplateReplacement Class

A server control that allows the regular controls to be displayed within the Edit Form and Pager templates.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v20.2.dll

NuGet Package: DevExpress.Web

Declaration

public class ASPxGridViewTemplateReplacement :
    WebControl,
    IWebControl,
    IStopLoadPostDataOnCallbackMarker

Remarks

The ASPxGridView enables you to provide any possible layout for its Edit Form and Pager using the GridViewTemplates.EditForm and GridViewTemplates.PagerBar templates respectively.

The ASPxGridViewTemplateReplacement control is designed only to display the regular Edit Form’s and Pager’s contents (edit cells, Update and Cancel buttons, pager) within a template.

...
<Templates>
    <EditForm>
        <dxtc:ASPxPageControl ID="ASPxPageControl1" runat="server" ActiveTabIndex="0">
            <TabPages>
                <dxtc:TabPage>
                    <ContentCollection>
                        <dxw:ContentControl runat="server">
                            <dxwgv:ASPxGridViewTemplateReplacement runat="server" ID="tr"
                            ReplacementType="EditFormEditors">
                            </dxwgv:ASPxGridViewTemplateReplacement>
                        </dxw:ContentControl>
                    </ContentCollection>
                </dxtc:TabPage>
            </TabPages>
        </dxtc:ASPxPageControl>
    <dxwgv:ASPxGridViewTemplateReplacement runat="server" ID="tr2" 
    ReplacementType="EditFormUpdateButton">
    </dxwgv:ASPxGridViewTemplateReplacement>

    <dxwgv:ASPxGridViewTemplateReplacement runat="server" ID="tr3" 
    ReplacementType="EditFormCancelButton">
    </dxwgv:ASPxGridViewTemplateReplacement>
    </EditForm>
</Templates>
...

Use the ASPxGridViewTemplateReplacement.ReplacementType property, to specify which controls are displayed by the control.

For an example, see Edit Form Template in the ASPxGridView demo.

To learn more, see Template Replacements .

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

Inheritance

See Also