Hi Andrew,
Please refer the below code snippet which will initiate the label control on code behind using ItemTemplates.
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 == "City")
{
System.Web.UI.WebControls.Label lbl = new Label();
lbl.ID = "Label1";
lbl.Init += new EventHandler(lbl_Init);
System.Web.UI.WebControls.Button btn = new Button();
btn.ID = "Button1";
btn.Text = "Click";
//Here we adding the DropDownListBox programatically using ITemplate Interface
TemplateClass mytemp = new TemplateClass(lbl,btn);
e.TableCellIdentity.Column.ItemTemplate = mytemp;
}
}
}
void lbl_Init(object sender, EventArgs e)
{
//throw new NotImplementedException();
Label lbl = (Label)sender;
GridRow gridrow = (GridRow)lbl.Parent.Parent.Parent;
string city = gridrow.Record.GetValue("City").ToString();
lbl.Text = city;
}
Please refer the sample from the below link, which illustrates the above:
http://www.syncfusion.com/support/user/uploads/Sample_2d644dee.zipPlease let me know if this helps you out.
Regards,
Raji