Sales
1-888-9DOTNET
|
Please refer the below steps involved to create ItemTemplates programatically: 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 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://websamples.syncfusion.com/samples/KB/Grid.Web/6.1.0.34/GGCItemTemplate/main.htm |