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

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.

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?

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

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.


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

I think any of these will solve my problem. I'll try the Hierarchical one.