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

RadListview Groups total

1 Answer 94 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Bassem
Top achievements
Rank 1
Bassem asked on 11 Mar 2014, 12:29 PM
My question is very simple i have a listview with multiple group in it ,what is the best way to display the to total of all the groups at once .the functionality of the radlistview is set to display the total of each group individually but i need to set the total of total in other words the somme of all the groups total .is that possible(is there any parameter inside the radlistview to set ) ? or should i do it from code 

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 14 Mar 2014, 08:53 AM
Hello Bassem,

Such functionality is not available out of the box, but it is possible to accomplish it in the code-behind, by handling the server-side ItemDataBound event of the grid (for retrieving the DataGroupItems aggregates) and the server-side PreRender event for setting the value.

If we use the ListView - DataGrouping online demo as a reference, we could add a Label control in the LayoutTemplate that will hold the sum of all groups aggregates:
<LayoutTemplate>
    <div class="listLayout">
        <asp:Label ID="AllGroupsSum" runat="server"></asp:Label>
        ...

And the code-behind for the ItemDataBound and PreRender events:
private double priceSum = 0;
 
protected void RadListView1_ItemDataBound(object sender, RadListViewItemEventArgs e)
{
    if (e.Item is RadListViewDataGroupItem)
    {
        RadListViewDataGroupItem item = e.Item as RadListViewDataGroupItem;
        priceSum += double.Parse(item.AggregatesValues["Price"].ToString());
    }
}
 
protected void RadListView1_PreRender(object sender, EventArgs e)
{
    RadListView listView = sender as RadListView;
    Label allGroupsSumLabel = listView.FindControl("AllGroupsSum") as Label;
    if (allGroupsSumLabel != null)
    {
        allGroupsSumLabel.Text = priceSum.ToString();  
    }
}

Please let me know if that helps with your requirement.


Regards,
Konstantin Dikov
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
Tags
ListView
Asked by
Bassem
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or