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

[Solved] RadGrid Runtime GridTemplateColumns

1 Answer 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vítor
Top achievements
Rank 1
Vítor asked on 04 Dec 2009, 05:35 PM
Hi all
I has trying to addColumns Dinamycally to a RadGrid
Here is the Code Snippet
 protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!IsPostBack) 
            { 
                // SET GRID VIEW 
                setGridEvoColumns(RadGridEvoStats); 
            } 
        } 
 
public void setGridEvoColumns(RadGrid Grid,ArrayList years, DataTable Source) 
        { 
 
            GridBoundColumn boundColumn; 
            GridTemplateColumn gtc; 
            StatsColumn sc; 
            StatsColumnHeader sch; 
 
 
            boundColumn = new GridBoundColumn(); 
            Grid.MasterTableView.Columns.Add(boundColumn); 
            boundColumn.HeaderText = "Country"
            boundColumn.DataField = "Country"
            boundColumn.UniqueName = "Country"
 
 
 
            string sufix = ""
            foreach (string year in years) 
            { 
                sufix = "_" + year; 
 
                gtc = new GridTemplateColumn(); 
                sc = new StatsColumn(); 
                sch = new StatsColumnHeader(); 
                 
                Grid.MasterTableView.Columns.Add(gtc); 
                 
                gtc.HeaderTemplate = sch
                gtc.ItemTemplate = sc
                 
            } 
        } 

I create a custom Header and ItemTemplate to the GridTemplateColumn

The Problem is when there are a PostBack on Page the TemplateColumns are cleared (lost their header values as Item values), but bound columns mantain theirs values and Headers.
I'm using NeedDataSource Event to Bound The Grid Also.

I Have already read this Article but it does not have an example with TemplateColumn.

Can anyone help me with this?

Thanks In Advance


1 Answer, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 07 Dec 2009, 08:24 AM
Hello VĂ­tor,

Creating template columns dynamically when the grid is declared on the page statically is not supported! you can create the entire grid + column before LoadViewState - ideally in OnInit.

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Vítor
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or