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

Customizing the RadGrid Items

7 Answers 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anders
Top achievements
Rank 1
Anders asked on 07 Jan 2009, 01:49 PM

I want to create a RadGrid that have databound items and look like this:

-------------------------------------------------------------

Heading1      Heading2      Heading3      …

 

Row1Cell1     Row1Cell3     Row1Cell3

Row1Cell4_That_should_span_all_columns

 

Row2Cell1     Row2Cell3     Row2Cell3

Row2Cell4_That_should_span_all_columns

 

….

 

-------------------------------------------------------------

I also want to enable sort on the headings (except for the cell that span all columns). 

7 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Jan 2009, 02:03 PM
Hello Anders,

You can refer to the following code library submission which demonstrates on how to span any given cell over a number of rows/columns. You can alter the logic according to your requirement.
span cells in grid over multiple positions

Thanks
Princy.


0
Anders
Top achievements
Rank 1
answered on 09 Jan 2009, 10:24 AM
Ok, that was an good example, and I got some new ideas from it.

Still I've struggle with my current problem that I want to have the last cell (Row1Cell4_That_should_span_all_columns) under the first cell.

-------------------------------------------------------------

Heading1      Heading2      Heading3      …

 

Row1Cell1     Row1Cell3     Row1Cell3

Row1Cell4_That_should_span_all_columns

 

….

 

-------------------------------------------------------------


Any Idea how to manage that?
0
Shinu
Top achievements
Rank 2
answered on 12 Jan 2009, 11:06 AM
Hi Anders,

Try out the following approach and let me know how it goes.

CS:
 protected void RadGrid2_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
    { 
        DataTable table = new DataTable(); 
        table.Columns.Add("Column1"); 
        table.Columns.Add("Column2"); 
        table.Columns.Add("Column3"); 
        
 
        table.Rows.Add(new object[] { "Cell11""Cell12""Cell12" }); 
        table.Rows.Add(new object[] { "Cell14" }); 
        table.Rows.Add(new object[] { "Cell21""Cell22""Cell23" }); 
        table.Rows.Add(new object[] { "Cell24" }); 
        table.Rows.Add(new object[] { "Cell31""Cell32""Cell33" }); 
        table.Rows.Add(new object[] { "Cell34" }); 
 
        RadGrid2.DataSource = table;   
    } 
 
 
  protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if ((e.Item is GridDataItem) && (e.Item.ItemType == GridItemType.AlternatingItem)) 
        { 
            GridDataItem altItem = (GridDataItem)e.Item; 
            altItem["Column1"].ColumnSpan = 3; 
            altItem["Column1"].BackColor = System.Drawing.Color.Pink; 
            altItem["Column2"].Visible = false
            altItem["Column3"].Visible = false
        } 
    } 


Regards
Shinu
0
Anders
Top achievements
Rank 1
answered on 12 Jan 2009, 11:14 AM
The thing is that I work with databound items and the code:

table.Rows.Add(

new object[] { "Cell11", "Cell12", "Cell12" });

 

table.Rows.Add(

new object[] { "Cell14" });

creates 2 rows.

I databound the grid to a DataTable in a DataSet. The table has 4 columns but the last one has very often a long string that I like to span under the other 3 columns.
I've looked at GridTemplateColumn and then I can embed a <table> but then I got problems with sorting on the 3 first columns.

 

0
Anders
Top achievements
Rank 1
answered on 15 Jan 2009, 11:19 AM
Have you found anything helpfull for me? Do I have to use the GridTemplateColumn?
0
Shinu
Top achievements
Rank 2
answered on 16 Jan 2009, 07:28 AM
Hi Anders,

I found the following code library submission which explains how to implement sorting of sub columns in GridTemplateColumns.But not sure whether this will help you.
Individual filtering and sorting for "sub-columns" in template column

One another suggestion will be to use a Hierarchical Grid where you can bind the master and detail table with the same Datasource. Show the first three columns in the Master table and the last column in the Detail table. Set HierarchyDefaultExpanded to true and hide the ExpandCollapse column.

Shinu
0
Anders
Top achievements
Rank 1
answered on 16 Jan 2009, 01:03 PM
Perfect!
I think any of these will solve my problem. I'll try the Hierarchical one. 
Tags
Grid
Asked by
Anders
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Anders
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or