How can I define templatefield with check box in ASP.NET with programming?

70 Views Asked by At

I want to define a template field with a checkbox on a grid view in asp.net like this:

TemplateField tf = new TemplateField();
tf.ItemTemplate = new System.Web.UI.WebControls.CheckBox();
gridView1.Columns.Add(tf);

but this error appears:

cannot implicitly convert 'System.Web.UI.WebControls.CheckBox' to 'System.Web.UI.ITemplate'.

1

There are 1 best solutions below

0
ArunPratap On

you can do that like this

on your grid load event

tfield = new TemplateField();
tfield.HeaderText = "CheckBox";
GridView1.Columns.Add(tfield);

on your Row Databound

CheckBox chk = new CheckBox();
 chk.ID = "chk";
 chk.Text = "View";
 // chk.CheckedChanged=event Name  you can add an event here
e.Row.Cells[2].Controls.Add(chk);