Hi Frndz,
Functionality: Dynamic added Checkbox inside Dynamicaly Gridview
To achieve this task,
Need to create constructor for Item Template
public class MyCustomTemplate : ITemplate
{
public void InstantiateIn(System.Web.UI.Control container)
{
}
}
Create Dynamic GridView set AutoGenerateColumn = False
GridView gvDynamic = new GridView();
Cretae Template Field Dynamic
TemplateField tf = new TemplateField();
tf.HeaderText = "Check";
tf.ItemTemplate = new MyCustomTemplate();
Added Template filed to GridView Column
Bind Gridview with Data Source
Added Gridview to One Panel Control for Display this GridView.
Logic :
GridView Logic
GridView gvDynamic = new GridView();
gvDynamic.Width = Unit.Pixel(700);
gvDynamic.BorderWidth = Unit.Pixel(0);
gvDynamic.AutoGenerateColumns = false;
gvDynamic.ShowFooter = true;
TemplateField tf = new TemplateField();
tf.HeaderText = "Check";
tf.ItemTemplate = new MyCustomTemplate();
gvDynamic.Columns.Add(tf);
gvDynamic.DataSource = dt;
gvDynamic.DataBind();
this.Panel1.Controls.Add(gvDynamic);
ItemTemplate Constructor Logic
public class MyCustomTemplate : ITemplate
{
public void InstantiateIn(System.Web.UI.Control container)
{
CheckBox cb = new CheckBox();
cb.ID = "checkbox";
cb.Text = "active";
container.Controls.Add(cb);
}
}
Hope this helpful!
Thanks