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

Iterating through columns, then items

3 Answers 236 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Samantha
Top achievements
Rank 1
Samantha asked on 05 Nov 2008, 10:03 PM
I need to create a merged cells type functionality (like http://www.telerik.com/community/forums/thread/b311D-ccatm.aspx) - this code checks through items and hard codes a column name.  How can I loop through all columns, checking if the previous column's value is equal to the current items?  I do not want to hard code column names.

3 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 07 Nov 2008, 01:11 PM
Hello Samantha,

You can use the RadGrid1.MasterTableView.RenderColumns collection, to get a reference to the collection of all rendered columns in the control- autogenerated and statically declared.

All the best,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Samantha
Top achievements
Rank 1
answered on 07 Nov 2008, 01:26 PM
Yes I know, but I am having difficulty combining the code to loop through the columns, and then the cells.  Can you post a code snippet?
0
Yavor
Telerik team
answered on 07 Nov 2008, 01:35 PM
Hello Samantha,

The code to iterate through all the rows in the control, and within each row, through all the cells, bases on the unique name of the column to which this cell belongs, would look like this:

.cs
 protected void RadGrid1_PreRender(object sender, EventArgs e)  
    {  
        foreach (GridDataItem dataItem in RadGrid1.MasterTableView.Items)  
        {  
            foreach (GridColumn column in RadGrid1.MasterTableView.RenderColumns)  
            {  
                if (column is GridBoundColumn)  
                {  
                    dataItem[column.UniqueName].Text = "test";  
                }  
            }  
        }  
    } 

I hope this helps.

Greetings,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Samantha
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Samantha
Top achievements
Rank 1
Share this question
or