GridViewDataColumn.EditItemTemplate Property
Gets or sets a template for displaying edit cells which correspond to the current column.
Namespace: DevExpress.Web
Assembly:
DevExpress.Web.v20.2.dll
NuGet Package:
DevExpress.Web
Declaration
[DefaultValue(null)]
public virtual ITemplate EditItemTemplate { get; set; }
<DefaultValue(Nothing)>
Public Overridable Property EditItemTemplate As ITemplate
Property Value
Type |
Default |
Description |
ITemplate |
*null* |
An object that implements the ITemplate interface.
|
Note
Once a template defined via the EditItemTemplate property is created within a control, it is instantiated within a container object of the GridViewEditItemTemplateContainer type. This container object exposes a set of specific properties to which the template’s child controls can be bound.
Example
This example shows how to use a two-way data-bound ASPxGridLookup in the edit form of ASPxGridView to update or insert new data.
MVC:
GridView - How to use GridLookup with single selection mode in EditForm
GridView - How to use GridLookup in EditForm in multiple selection mode
View Example
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
public partial class _Default : System.Web.UI.Page
{
protected void glCategory_Load(object sender, EventArgs e) {
(sender as ASPxGridLookup).GridView.Width = new Unit(500, UnitType.Pixel);
}
protected void grid_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e) {
throw new CallbackException("Operation is not allowed in demonstration mode");
}
protected void grid_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e) {
throw new CallbackException("Operation is not allowed in demonstration mode");
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for CallbackException
/// </summary>
public class CallbackException : Exception
{
public CallbackException(string message)
: base(message)
{
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="DevExpress.Web.v15.1, Version=15.1.2.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web" TagPrefix="dx" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to use two-way data-bound ASPxGridLookup in edit form of ASPxGridView to edit data</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dx:ASPxGridView ID="grid" runat="server" AutoGenerateColumns="False" DataSourceID="dsProducts"
KeyFieldName="ProductID" OnRowInserting="grid_RowInserting" OnRowUpdating="grid_RowUpdating">
<Columns>
<dx:GridViewDataTextColumn FieldName="ProductID" ReadOnly="True" Visible="False"
VisibleIndex="0">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="ProductName" VisibleIndex="0">
</dx:GridViewDataTextColumn>
<dx:GridViewDataComboBoxColumn FieldName="CategoryID" VisibleIndex="1">
<PropertiesComboBox DataSourceID="dsCategories" TextField="CategoryName" ValueField="CategoryID"
ValueType="System.Int32">
</PropertiesComboBox>
<EditItemTemplate>
<dx:ASPxGridLookup ID="glCategory" runat="server" AutoGenerateColumns="False"
DataSourceID="dsCategories" KeyFieldName="CategoryID" OnLoad="glCategory_Load"
TextFormatString="{1}" Value='<%# Bind("CategoryID") %>' Width="260px">
<GridViewProperties>
<SettingsBehavior AllowFocusedRow="True" AllowSelectByRowClick="True"
AllowSelectSingleRowOnly="True" />
<SettingsBehavior AllowFocusedRow="True" AllowSelectByRowClick="True"
AllowSelectSingleRowOnly="True" />
</GridViewProperties>
<Columns>
<dx:GridViewDataTextColumn FieldName="CategoryID" ReadOnly="True"
Visible="False" VisibleIndex="0">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="CategoryName" VisibleIndex="1">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Description" VisibleIndex="2">
</dx:GridViewDataTextColumn>
</Columns>
</dx:ASPxGridLookup>
</EditItemTemplate>
</dx:GridViewDataComboBoxColumn>
<dx:GridViewDataTextColumn FieldName="UnitPrice" VisibleIndex="2">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="UnitsOnOrder" VisibleIndex="4">
</dx:GridViewDataTextColumn>
<dx:GridViewCommandColumn VisibleIndex="6" ShowEditButton="True" ShowNewButton="True"/>
</Columns>
</dx:ASPxGridView>
</div>
<asp:SqlDataSource ID="dsProducts" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
InsertCommand="INSERT INTO [Products] ([ProductName], [CategoryID], [UnitPrice], [UnitsOnOrder]) VALUES (@ProductName, @CategoryID, @UnitPrice, @UnitsInStock, @UnitsOnOrder)"
SelectCommand="SELECT [ProductID], [ProductName], [CategoryID], [UnitPrice], [UnitsOnOrder] FROM [Products]"
UpdateCommand="UPDATE [Products] SET [ProductName] = @ProductName, [CategoryID] = @CategoryID, [UnitPrice] = @UnitPrice, [UnitsOnOrder] = @UnitsOnOrder WHERE [ProductID] = @ProductID">
<DeleteParameters>
<asp:Parameter Name="ProductID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="ProductName" Type="String" />
<asp:Parameter Name="CategoryID" Type="Int32" />
<asp:Parameter Name="UnitPrice" Type="Decimal" />
<asp:Parameter Name="UnitsInStock" Type="Int16" />
<asp:Parameter Name="UnitsOnOrder" Type="Int16" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="ProductName" Type="String" />
<asp:Parameter Name="CategoryID" Type="Int32" />
<asp:Parameter Name="UnitPrice" Type="Decimal" />
<asp:Parameter Name="UnitsInStock" Type="Int16" />
<asp:Parameter Name="UnitsOnOrder" Type="Int16" />
<asp:Parameter Name="ProductID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="dsCategories" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CategoryID], [CategoryName], [Description] FROM [Categories]">
</asp:SqlDataSource>
</form>
</body>
</html>
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
''' <summary>
''' Summary description for CallbackException
''' </summary>
Public Class CallbackException
Inherits Exception
Public Sub New(ByVal message As String)
MyBase.New(message)
End Sub
End Class
<%@ Page Language="vb" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%@ Register Assembly="DevExpress.Web.v15.1, Version=15.1.2.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web" TagPrefix="dx" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to use two-way data-bound ASPxGridLookup in edit form of ASPxGridView to edit data</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dx:ASPxGridView ID="grid" runat="server" AutoGenerateColumns="False" DataSourceID="dsProducts"
KeyFieldName="ProductID" OnRowInserting="grid_RowInserting" OnRowUpdating="grid_RowUpdating">
<Columns>
<dx:GridViewDataTextColumn FieldName="ProductID" ReadOnly="True" Visible="False"
VisibleIndex="0">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="ProductName" VisibleIndex="0">
</dx:GridViewDataTextColumn>
<dx:GridViewDataComboBoxColumn FieldName="CategoryID" VisibleIndex="1">
<PropertiesComboBox DataSourceID="dsCategories" TextField="CategoryName" ValueField="CategoryID"
ValueType="System.Int32">
</PropertiesComboBox>
<EditItemTemplate>
<dx:ASPxGridLookup ID="glCategory" runat="server" AutoGenerateColumns="False"
DataSourceID="dsCategories" KeyFieldName="CategoryID" OnLoad="glCategory_Load"
TextFormatString="{1}" Value='<%#Bind("CategoryID")%>' Width="260px">
<GridViewProperties>
<SettingsBehavior AllowFocusedRow="True" AllowSelectByRowClick="True"
AllowSelectSingleRowOnly="True" />
<SettingsBehavior AllowFocusedRow="True" AllowSelectByRowClick="True"
AllowSelectSingleRowOnly="True" />
</GridViewProperties>
<Columns>
<dx:GridViewDataTextColumn FieldName="CategoryID" ReadOnly="True"
Visible="False" VisibleIndex="0">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="CategoryName" VisibleIndex="1">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Description" VisibleIndex="2">
</dx:GridViewDataTextColumn>
</Columns>
</dx:ASPxGridLookup>
</EditItemTemplate>
</dx:GridViewDataComboBoxColumn>
<dx:GridViewDataTextColumn FieldName="UnitPrice" VisibleIndex="2">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="UnitsOnOrder" VisibleIndex="4">
</dx:GridViewDataTextColumn>
<dx:GridViewCommandColumn VisibleIndex="6" ShowEditButton="True" ShowNewButton="True"/>
</Columns>
</dx:ASPxGridView>
</div>
<asp:SqlDataSource ID="dsProducts" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
InsertCommand="INSERT INTO [Products] ([ProductName], [CategoryID], [UnitPrice], [UnitsOnOrder]) VALUES (@ProductName, @CategoryID, @UnitPrice, @UnitsInStock, @UnitsOnOrder)"
SelectCommand="SELECT [ProductID], [ProductName], [CategoryID], [UnitPrice], [UnitsOnOrder] FROM [Products]"
UpdateCommand="UPDATE [Products] SET [ProductName] = @ProductName, [CategoryID] = @CategoryID, [UnitPrice] = @UnitPrice, [UnitsOnOrder] = @UnitsOnOrder WHERE [ProductID] = @ProductID">
<DeleteParameters>
<asp:Parameter Name="ProductID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="ProductName" Type="String" />
<asp:Parameter Name="CategoryID" Type="Int32" />
<asp:Parameter Name="UnitPrice" Type="Decimal" />
<asp:Parameter Name="UnitsInStock" Type="Int16" />
<asp:Parameter Name="UnitsOnOrder" Type="Int16" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="ProductName" Type="String" />
<asp:Parameter Name="CategoryID" Type="Int32" />
<asp:Parameter Name="UnitPrice" Type="Decimal" />
<asp:Parameter Name="UnitsInStock" Type="Int16" />
<asp:Parameter Name="UnitsOnOrder" Type="Int16" />
<asp:Parameter Name="ProductID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="dsCategories" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CategoryID], [CategoryName], [Description] FROM [Categories]">
</asp:SqlDataSource>
</form>
</body>
</html>
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports DevExpress.Web
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub glCategory_Load(ByVal sender As Object, ByVal e As EventArgs)
TryCast(sender, ASPxGridLookup).GridView.Width = New Unit(500, UnitType.Pixel)
End Sub
Protected Sub grid_RowInserting(ByVal sender As Object, ByVal e As DevExpress.Web.Data.ASPxDataInsertingEventArgs)
Throw New CallbackException("Operation is not allowed in demonstration mode")
End Sub
Protected Sub grid_RowUpdating(ByVal sender As Object, ByVal e As DevExpress.Web.Data.ASPxDataUpdatingEventArgs)
Throw New CallbackException("Operation is not allowed in demonstration mode")
End Sub
End Class
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the EditItemTemplate property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
See Also