Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
TemplateColumn tc = new TemplateColumn();
tc.HeaderText = [Text of column header];
tc.ItemTemplate = [b][ITemplate type][/b];
[color green]// dg is the DataGrid control[/color]
dg.Columns.Add(tc);
private class CheckBoxTemplate : ITemplate
{
// Implementation of ITemplate
public void InstantiateIn(System.Web.UI.Control container)
{
[color green]// Create a check box[/color]
CheckBox cb = new CheckBox();
[color green]// Make the check box appear
// in the column[/color]
container.Controls.Add(cb);
}
}
private class CheckBoxTemplate : ITemplate
{
public void InstantiateIn(System.Web.UI.Control
container)
{
[color green]// Create a check box[/color]
CheckBox cb = new CheckBox();
[color green]//Attach method to delegate[/color]
[b]cb.DataBinding +=
new System.EventHandler(this.BindCheckBox);[/b]
container.Controls.Add(cb);
}
[color green]//Method that responds to the
DataBinding event [/color][b]
private void BindCheckBox(object sender,
System.EventArgs e)
{
CheckBox cb = (CheckBox)sender;
DataGridItem container =
(DataGridItem)cb.NamingContainer;
cb.Checked = [Data binding expression];
}
}[/b]
[b]cb.DataBinding +=
new System.EventHandler(this.BindCheckBox);[/b]
[b]CheckBox cb = (CheckBox)sender;[/b]
[b]DataGridItem container =
(DataGridItem)cb.NamingContainer;[/b]
[b]cb.Checked =
(DataBinder.Eval(container.DataItem, "ItemID").ToString() == "10";);[/b]
TemplateColumn tc = new TemplateColumn();
tc.HeaderText = [Text of column header];
[color green]//Isn't this beautiful? [/color]
[b]tc.ItemTemplate = new CheckBoxTemplate();[/b]
[color green]// dg is the DataGrid control[/color]
dg.Columns.Add(tc);