Articles in this section
Category / Section

How to create ItemTemplates programatically in GridgroupingControl?

1 min read


Please refer the below steps involved to create ItemTemplates programatically:

  • In QueryCellStyleInfo event an instance for the TemplateClass of that particular item should be created and assigned it to the EditItemTemplate of that column.


protected void GridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)


//Look for the RecordField and AlternateField Cell.

if (e.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell || e.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell)


//Look for the Column Name "Column2" in the GridGroupingControl when it get rendered

if (e.TableCellIdentity.Column.Name == "Column2")


Syncfusion.Web.UI.WebControls.Shared.DropDownCalendarControl dropdown = new DropDownCalendarControl();

dropdown.ClientObjectId = "ddcal";


dropdown.Format = DateTimeFormatType.CustomString;

dropdown.Attributes.Add("onclick", "fun1(this);");


dropdown.AutoPostBack = true;

//Here we adding the DropDownListBox programatically using ITemplate Interface

TemplateClass mytemp = new TemplateClass(dropdown);

e.TableCellIdentity.Column.EditItemTemplate = mytemp;





Protected Sub GridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As GridTableCellStyleInfoEventArgs)

'Look for the RecordField and AlternateField Cell.

If e.TableCellIdentity.TableCellType = GridTableCellType.RecordFieldCell OrElse e.TableCellIdentity.TableCellType = GridTableCellType.AlternateRecordFieldCell Then

'Look for the Column Name "Column2" in the GridGroupingControl when it get rendered

If e.TableCellIdentity.Column.Name = "Column2" Then

Dim dropdown As Syncfusion.Web.UI.WebControls.Shared.DropDownCalendarControl = New DropDownCalendarControl()

dropdown.ClientObjectId = "ddcal"


dropdown.Format = DateTimeFormatType.CustomString

dropdown.Attributes.Add("onclick", "fun1(this);")


dropdown.AutoPostBack = True

'Here we adding the DropDownListBox programatically using ITemplate Interface

Dim mytemp As TemplateClass = New TemplateClass(dropdown)

e.TableCellIdentity.Column.EditItemTemplate = mytemp

End If

End If

End Sub

  • Define the TemplateClass which is inherited from ITemplate. Please refer the below code snippet which illustrates this:


public class TemplateClass : ITemplate


private Control m_ctrlChildControl = null;

public TemplateClass(Control ctrlChildControl)


m_ctrlChildControl = ctrlChildControl;


public void InstantiateIn(Control container)






Public Class TemplateClass : Implements ITemplate

Private m_ctrlChildControl As Control = Nothing

Public Sub New(ByVal ctrlChildControl As Control)

m_ctrlChildControl = ctrlChildControl

End Sub

Public Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn


End Sub

End Class


Did you find this information helpful?
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment