Hi Rob,
Thank you for contacting us.
I have to say that there is no built-in way for achieving the desired result and I am not sure if it is possible to achieve it with custom implementation as well, because the grid's structure is not designed to allow such layout.
The only approach that I could think of will require to use DetailItemTemplate for the second hierarchy level and customize it in such manner, so it could simulate a header. However, the DetailItemTemplate will be displayed after the item and could not be displayed above it:
And the code-behind:
protected
void
RadGrid1_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
DataTable table =
new
DataTable();
table.Columns.Add(
"ID"
,
typeof
(
int
));
table.Columns.Add(
"FirstName"
,
typeof
(
string
));
table.Columns.Add(
"LastName"
,
typeof
(
string
));
table.Columns.Add(
"Age"
,
typeof
(
int
));
table.Columns.Add(
"Image"
,
typeof
(DateTime));
table.Columns.Add(
"BoolValue"
,
typeof
(Boolean));
for
(
int
i = 0; i < 5; i++)
{
table.Rows.Add(i,
"value"
+ i,
"value"
+ i, 20 + i, DateTime.Now.AddDays(i), i % 2 == 0);
}
(sender
as
RadGrid).DataSource = table;
}
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem item = e.Item
as
GridDataItem;
if
(item.OwnerTableView.Name ==
"Level2"
)
{
item.DetailTemplateItemDataCell.ColumnSpan = 1;
TableRow detailRow = item.DetailTemplateItemDataCell.Parent
as
TableRow;
bool
isFirst =
true
;
foreach
(GridColumn column
in
item.OwnerTableView.RenderColumns)
{
if
(column.Visible && column.Display && column.OrderIndex >= 0)
{
if
(!isFirst)
{
TableCell nextCell =
new
TableCell();
detailRow.Cells.Add(nextCell);
}
detailRow.Cells[detailRow.Cells.Count - 1].Text = column.HeaderText;
detailRow.Cells[detailRow.Cells.Count - 1].CssClass =
"rgHeader"
;
isFirst =
false
;
}
}
}
}
}
If any questions related to the built-in functionality of the control arise, please feel free to contact us again.
Regards,
Konstantin Dikov
Telerik
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items