We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to create ItemTemplates programatically in GridgroupingControl?

 

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.

C#

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.CustomFormat="MM/dd/yy";

dropdown.Format = DateTimeFormatType.CustomString;

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

//Response.Write(dropdown.MinValue.Year.ToString());

dropdown.AutoPostBack = true;

//Here we adding the DropDownListBox programatically using ITemplate Interface

TemplateClass mytemp = new TemplateClass(dropdown);

e.TableCellIdentity.Column.EditItemTemplate = mytemp;

}

}

}

VB

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.CustomFormat="MM/dd/yy"

dropdown.Format = DateTimeFormatType.CustomString

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

'Response.Write(dropdown.MinValue.Year.ToString());

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:

C#

public class TemplateClass : ITemplate

{

private Control m_ctrlChildControl = null;

public TemplateClass(Control ctrlChildControl)

{

m_ctrlChildControl = ctrlChildControl;

}

public void InstantiateIn(Control container)

{

container.Controls.Add(m_ctrlChildControl);

}

}

VB

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

container.Controls.Add(m_ctrlChildControl)

End Sub

End Class

Sample:

http://help.syncfusion.com/support/samples/KB/grid.web/6.1.0.34/GGCItemTemplate/ItemTemplate.zip

Article ID: Published Date: Last Revised Date: Platform: Control:
714 04/30/2011 07/10/2014 ASP.NET Web Forms (Classic) GridGroupingControl
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon