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

[Solved] help needed with group header

7 Answers 390 Views
Grid
This is a migrated thread and some comments may be shown as answers.
andieje
Top achievements
Rank 1
andieje asked on 10 May 2008, 08:39 AM
Hi

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

Sort by
0
andieje
Top achievements
Rank 1
answered on 12 May 2008, 07:35 PM
Hi

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
0
Shinu
Top achievements
Rank 2
answered on 13 May 2008, 06:26 AM
Hi,

Go through the following help document links.

Performing calculations in group header
Customizing GridGroupHeaderItem

Shinu
0
andieje
Top achievements
Rank 1
answered on 13 May 2008, 10:09 AM
Dear Shinu,

I've already looked at those links and they did not help me.

andrea
0
andieje
Top achievements
Rank 1
answered on 27 May 2008, 10:54 AM
Hi

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
0
Yavor
Telerik team
answered on 27 May 2008, 11:56 AM
Hello andieje,

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
0
andieje
Top achievements
Rank 1
answered on 27 May 2008, 04:16 PM
Hi

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
0
Yavor
Telerik team
answered on 30 May 2008, 10:13 AM
Hello andieje,

In this case, you will need to take a custom approach. The logic is roughly as follows:

  1. You get a reference to the GridGroupHeaderItems for the control, for example in the PreRender event handler.
  2. 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
Tags
Grid
Asked by
andieje
Top achievements
Rank 1
Answers by
andieje
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Yavor
Telerik team
Share this question
or