This is a migrated thread and some comments may be shown as answers.

Dynamic column problem

1 Answer 50 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Art
Top achievements
Rank 1
Art asked on 30 Mar 2014, 08:51 AM
Hello,

I am dynamically adding a GridTemplateColumn to the grid. The column is added as required the first page load but on each following postback I am getting a new empty columm with header "Action". Any Idea?

 protected void Page_Init(object sender, EventArgs e)
        {
   
              var col = this.requestGrid.MasterTableView.Columns.FindByUniqueNameSafe("ActionId");
               
                GridTemplateColumn actionColumn = new GridTemplateColumn();
                this.requestGrid.MasterTableView.Columns.Add(actionColumn);
                actionColumn.ItemTemplate = new ActionTemplate("actionID");                
                
                actionColumn.DataField = "ActionID";
                
                actionColumn.HeaderText = "Action";
               
        }

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 31 Mar 2014, 07:24 AM
Hi,

When generating a grid in the Page_Init event handler, grid columns should be added to the Columns collection of the MasterTableView after their attributes are set.

C#:
protected void Page_Init(object sender, EventArgs e)
  {                             
    GridTemplateColumn actionColumn = new GridTemplateColumn();
    actionColumn.ItemTemplate = new ActionTemplate("actionID");                    
    actionColumn.DataField = "ActionID";                
    actionColumn.HeaderText = "Action";
    this.requestGrid.MasterTableView.Columns.Add(actionColumn);              
  }

Thanks,
Shinu
Tags
Grid
Asked by
Art
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or