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")
{
harmandeep.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;
}
}
}
Join the conversation! Your thoughts help the community grow.