How can I add a template field with a checkbox to my DetailsView object through C# code-behind? I’m having trouble figuring it out from reading the asp.net code.
I already have the TemplateField and CheckBox object instantiated with values assigned to the properties. But when I use Fields.Add() the checkbox doesn’t show-up.
TemplateField tf_ForMalls = new TemplateField();
tf_ForMalls.HeaderText = "For Malls";
CheckBox chk_ForMalls = new CheckBox();
chk_ForMalls.ID = "chkDelete";
tf_ForMalls.ItemTemplate = chk_ForMalls as ITemplate;
dv_SpotDetail.Fields.Add(tf_ForMalls);
You will need a custom class derived from ITemplate to get this working
Then in the code
You can have the constructor to pass in the parameters for ‘control id’ or specifying the ListItemType
Hope this helps