ASPxGridViewTemplateReplacement Class
Displays regular elements (edit cells, buttons, or a pager) within the Edit Form or Pager templates.
Namespace: DevExpress.Web
Assembly: DevExpress.Web.v24.2.dll
Declaration
public class ASPxGridViewTemplateReplacement :
WebControl,
IWebControl,
IStopLoadPostDataOnCallbackMarker
Remarks
Template replacements allow you to add standard grid elements (edit cells, buttons, or a pager) to the EditForm or PagerBar templates.
To create a template replacement, add an object of the ASPxGridViewTemplateReplacement
class to a template and specify the ReplacementType property.
Design-Time Example
The code sample below adds ASPxPageControl to the edit form template and uses the ASPxGridViewTemplateReplacement
objects to render an edit form with edit cells and buttons in a custom position.
<dx:ASPxGridView ID="grid" runat="server" AutoGenerateColumns="False" KeyFieldName="EmployeeID"
OnRowUpdating="grid_RowUpdating" OnRowInserting="grid_RowInserting">
<Templates>
<EditForm>
<div style="padding: 4px 3px 4px">
<dx:ASPxPageControl ID="ASPxPageControl1" runat="server" Width="100%">
<TabPages>
<dx:TabPage Text="Info" Visible="true">
<ContentCollection>
<dx:ContentControl runat="server">
<dx:ASPxGridViewTemplateReplacement ID="Editors" runat="server"
ReplacementType="EditFormEditors" />
</dx:ContentControl>
</ContentCollection>
</dx:TabPage>
<dx:TabPage Text="Notes" Visible="true">
<ContentCollection>
<dx:ContentControl runat="server">
<dx:ASPxMemo runat="server" ID="notesEditor"
Text='<%# Eval("Notes")%>' Width="100%" Height="93px" />
</dx:ContentControl>
</ContentCollection>
</dx:TabPage>
</TabPages>
</dx:ASPxPageControl>
</div>
<div style="text-align: right; padding: 2px">
<dx:ASPxGridViewTemplateReplacement ID="UpdateButton" runat="server"
ReplacementType="EditFormUpdateButton" />
<dx:ASPxGridViewTemplateReplacement ID="CancelButton" runat="server"
ReplacementType="EditFormCancelButton" />
</div>
</EditForm>
</Templates>
</dx:ASPxGridView>
protected void grid_RowUpdating(object sender, ASPxDataUpdatingEventArgs e){
e.NewValues["Notes"] = GetMemoText();
}
protected void grid_RowInserting(object sender, ASPxDataInsertingEventArgs e){
e.NewValues["Notes"] = GetMemoText();
}
protected string GetMemoText(){
ASPxPageControl pageControl = grid.FindEditFormTemplateControl("pageControl") as ASPxPageControl;
ASPxMemo memo = pageControl.FindControl("notesEditor") as ASPxMemo;
return memo.Text;
}
Runtime Example
The following example creates an edit form 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;
}
}
Implements
Inheritance
Object
Control
WebControl
ASPxGridViewTemplateReplacement
See Also