manishsawant
MIS
Hi,
I am using ASP.net 2.0 and am creating TemplateFields and BoundColumns for a GridView at runtime. I have created a class for creating buttons which implements ITemplate interface. Before binding the grid i have written.
TemplateField t = new TemplateField();
t.ItemTemplate = new CreateItemTemplatePushButton("btnSelectAll", "Select All", "Select All");
GridView1.Columns.Add(t);
Below is the class which implements ITemplate.
public class CreateItemTemplatePushButton : ITemplate
{
string strColumnText;
string strButtonName;
string strCommandName;
bool Visibile = true;
bool Enable = true;
public CreateItemTemplatePushButton(string ButtonName, string ColText, string CommandName)
{
this.strColumnText = ColText;
this.strButtonName = ButtonName;
this.strCommandName = CommandName;
}
public void InstantiateIn(Control objContainer)
{
Button btn = new Button();
btn.CommandName = strCommandName;
btn.ID = strButtonName;
btn.Text = strColumnText;
btn.EnableViewState = true;
objContainer.Controls.Add(btn);
}
}
The grid comes up very well, but when ever there is a postback the TemplateField disappears and the BoundColumns remain. I have tried EnableViewState=true; but it doesnt make a difference. Has anyone come across this problem.
Awaiting your advice.
Thanks,
Manish
I am using ASP.net 2.0 and am creating TemplateFields and BoundColumns for a GridView at runtime. I have created a class for creating buttons which implements ITemplate interface. Before binding the grid i have written.
TemplateField t = new TemplateField();
t.ItemTemplate = new CreateItemTemplatePushButton("btnSelectAll", "Select All", "Select All");
GridView1.Columns.Add(t);
Below is the class which implements ITemplate.
public class CreateItemTemplatePushButton : ITemplate
{
string strColumnText;
string strButtonName;
string strCommandName;
bool Visibile = true;
bool Enable = true;
public CreateItemTemplatePushButton(string ButtonName, string ColText, string CommandName)
{
this.strColumnText = ColText;
this.strButtonName = ButtonName;
this.strCommandName = CommandName;
}
public void InstantiateIn(Control objContainer)
{
Button btn = new Button();
btn.CommandName = strCommandName;
btn.ID = strButtonName;
btn.Text = strColumnText;
btn.EnableViewState = true;
objContainer.Controls.Add(btn);
}
}
The grid comes up very well, but when ever there is a postback the TemplateField disappears and the BoundColumns remain. I have tried EnableViewState=true; but it doesnt make a difference. Has anyone come across this problem.
Awaiting your advice.
Thanks,
Manish