I have a gridview that populates checkboxes dynamically in the headerTemplate of a gridview. The header is a checkbox and a dynamic text/label. However i can't get the headertemplate to display the text:
PageLoad:
foreach (Module m in listModule)
{
TemplateField tfield = new TemplateField();
CheckBox cbAll = new CheckBox();
tfield.HeaderTemplate = new TickColumn();
tfield.HeaderText = m.ModuleName; //<- This is not getting displayed.
gvUsers.Columns.Add(tfield);
}
class TickColumn : ITemplate
{
public void InstantiateIn(System.Web.UI.Control container)
{
CheckBox cbAll = new CheckBox();
cbAll.ID = "cbAll";
container.Controls.Add(cbAll);
}
}
For some reason, the HeaderText is not getting displayed.
Alternatively I have tried adding a label inside in the class but there i have no idea as of how to pass the value in:
static string lblname;
PageLoad:
foreach (Module m in listModule)
{
TemplateField tfield = new TemplateField();
CheckBox cbAll = new CheckBox();
tfield.HeaderTemplate = new TickColumn();
lblname = m.ModuleName;
gvUsers.Columns.Add(tfield);
}
class TickColumn : ITemplate
{
public void InstantiateIn(System.Web.UI.Control container)
{
CheckBox cbAll = new CheckBox();
Label lbl = new Label();
lbl.Text = lblName;
cbAll.ID = "cbAll";
container.Controls.Add(cbAll);
container.Controls.Add(lbl);
}
}
With this code, every dynamic column label's text becomes the same, the last element name get display throughout all the labels. How can i work my way around this?