Hi There,
I'm trying to add some extra GridTemplateColumns on my Page_Init using my own custom template class. When the page loads the first time, everything is fine and dandy. Yet after a postback from a filter or paging command, things go horribly wrong. More specifically, the extra columns that I i'm adding on Page_Init remain, but for every postback, an extra set of blank columns are added to the grid. My initial thought was to just wrap my Page_Init inside a if(!isPostBack) statement, but then no extra columns show at all after a postback. Please help!
Here's my Page_Init:
... and my custom template looks like this.
Also, my NeedDataSource uses the same datasource that I bind to on my Page_Load:
I'm trying to add some extra GridTemplateColumns on my Page_Init using my own custom template class. When the page loads the first time, everything is fine and dandy. Yet after a postback from a filter or paging command, things go horribly wrong. More specifically, the extra columns that I i'm adding on Page_Init remain, but for every postback, an extra set of blank columns are added to the grid. My initial thought was to just wrap my Page_Init inside a if(!isPostBack) statement, but then no extra columns show at all after a postback. Please help!
Here's my Page_Init:
protected void Page_Init(object sender, EventArgs e) |
{ |
ListBuilderTableAdapters.listsTableAdapter listAdapter = new ListBuilderTableAdapters.listsTableAdapter(); |
ListBuilder.listsDataTable dt = listAdapter.GetActive(); |
foreach (ListBuilder.listsRow dr in dt.Rows) |
{ |
GridTemplateColumn gtc = new GridTemplateColumn(); |
gtc.HeaderText = dr.list_name; |
gtc.ItemTemplate = new MailingListTemplate(dr.list_name, dr.id); |
mlRadGrid.MasterTableView.Columns.Add(gtc); |
} |
} |
... and my custom template looks like this.
public class MailingListTemplate : ITemplate |
{ |
protected string Text; |
protected int listID; |
public MailingListTemplate(string Text, int listID) |
{ |
this.listID = listID; |
this.Text = Text; |
} |
public void InstantiateIn(Control container) |
{ |
HiddenField hf = new HiddenField(); |
hf.Value = listID.ToString(); |
CheckBox cb = new CheckBox(); |
container.Controls.Add(hf); |
container.Controls.Add(cb); |
} |
} |
Also, my NeedDataSource uses the same datasource that I bind to on my Page_Load:
protected void mlRadGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e) |
{ |
mlRadGrid.DataSource = recipientAdapter.GetUnique(); |
} |