I need some help with a group header.
I am going to simplify the data in my grid to help with this example. Lets says my grid has a column called row no and that the rows in the grid are ordered into groups which have intervals of 10. So for example the first group is rows 1 to 10 and the second group is rows 1 to 20.
I would like the header for group 1 to say 'Rows 1 to 10' and the header for group 2 to say 'Rows 2 to 20'
This would require knowing information about the first and last row in the group when the it comes to creating the group header. I normally create group headers like this:
Private Sub dgStock_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.GridItemEventArgs) Handles dgStock.ItemDataBound
If TypeOf e.Item Is GridGroupHeaderItem Then
Dim item As GridGroupHeaderItem = CType(e.Item, GridGroupHeaderItem)
Dim groupDataRow As DataRowView = CType(e.Item.DataItem, DataRowView)
'Clear the present text of the cell
item.DataCell.Text =
""
Dim column As DataColumn
For Each column In groupDataRow.DataView.Table.Columns
'item.DataCell.Text = item.DataCell.Text & " " & column.ColumnName
'Check the condition and add only the field you need
If column.ColumnName = "StockType" Then
item.DataCell.Text = groupDataRow(
"StockType").ToString()
Exit For
End If
Next column
Naturally this method of adding a group header won't let me do what i want to do so I was hoping you could please advise.
thanks
7 Answers, 1 is accepted
I was just wondering if someone in the support team would be able to look at this questiob because other questions i have asked after this one have already been answered (thanks for asnwering those by the way!)
andrea
Go through the following help document links.
Performing calculations in group header
Customizing GridGroupHeaderItem
Shinu
I've already looked at those links and they did not help me.
andrea
I posted this question over 2 weeks ago and it has not been looked at by anyone in technical support. I would be really grateful if someone could give me some advice on this as soon as possible.
I've already looked at the help pages suggested by the other participant in this thread. I've already looked at all of the help pages for the grid and couldn't find a solution so I would really appreciate some hands-on help
Many thanks in advance
andrea
You can use the group aggregate functions, and the group footer, to get additional information on the items nested in each group. For example, as in the code snippets below:
.aspx
| <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="AccessDataSource1" GridLines="None" |
| OnItemDataBound="RadGrid1_ItemDataBound1" ShowGroupPanel="True" OnPreRender="RadGrid1_PreRender1"> |
| <MasterTableView CommandItemDisplay="Top" |
| ShowGroupFooter="true" |
| AutoGenerateColumns="False" DataKeyNames="EmployeeID" DataSourceID="AccessDataSource1"> |
| <GroupByExpressions> |
| <telerik:GridGroupByExpression> |
| <GroupByFields> |
| <telerik:GridGroupByField FieldName="EmployeeID" /> |
| </GroupByFields> |
| <SelectFields> |
| <telerik:GridGroupByField FieldName="EmployeeID" /> |
| </SelectFields> |
| </telerik:GridGroupByExpression> |
| </GroupByExpressions> |
| <RowIndicatorColumn Visible="False"> |
| <HeaderStyle Width="20px" /> |
| </RowIndicatorColumn> |
| <ExpandCollapseColumn Resizable="False" Visible="False"> |
| <HeaderStyle Width="20px" /> |
| </ExpandCollapseColumn> |
| <Columns> |
| <telerik:GridEditCommandColumn> |
| </telerik:GridEditCommandColumn> |
| <telerik:GridBoundColumn |
| Aggregate="Count" |
| DataField="EmployeeID" DataType="System.Int32" HeaderText="EmployeeID" |
| ReadOnly="True" SortExpression="EmployeeID" UniqueName="EmployeeID"> |
| </telerik:GridBoundColumn> |
.cs
| protected void RadGrid1_PreRender1(object sender, EventArgs e) |
| { |
| GridGroupHeaderItem groupHeader = (GridGroupHeaderItem)RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader)[0]; |
| GridGroupFooterItem groupfooter = (GridGroupFooterItem)RadGrid1.MasterTableView.GetItems(GridItemType.GroupFooter)[0]; |
| groupHeader.DataCell.Text = groupfooter.Cells[4].Text; |
| } |
Naturally, you can also hide the group footer or use only the group footer to display similar information.
I hope this suggestion helps.
Best wishes,
Yavor
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Thanks for your reply but I would ask you to re-read my question again please. If you do you will see that a group aggregate function is not appropriate for my needs. I want to extract some information from both the first and last item in the group and display that in the group header. That is not something you can do with an aggregate function. I need to know how to loop around the group items in the item data binding event to get info from the first and last items in the group
thanks
amdrea
In this case, you will need to take a custom approach. The logic is roughly as follows:
- You get a reference to the GridGroupHeaderItems for the control, for example in the PreRender event handler.
- Then, you can iterate through all the dataItems in the control (RadGrid1.MasterTableView.Items), and compare the fields that you have grouped on. If the values match, i.e. the items belong to the same group, you can extract the values from the relevant cell.
I hope this suggestion helps.
Regards,
Yavor
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center