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

Display Total in footer

7 Answers 384 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Senthil ramna
Top achievements
Rank 1
Senthil ramna asked on 17 Nov 2010, 10:58 AM
I have a main Grid and inside the item template of that grid i have placed 6 grids.
I have done this as i have to export to excel all the six grids data into one excel. This is working fine. The thing i am not able to figure out is how to display the total for some of the columns of my first grid.
below is my code block for the first grid.
<telerik:RadGrid ID="radGridWrapper" runat="server" Skin="Web20" ShowHeader="false" BorderStyle="None" Width="100%" 
                    onexcelmlexportstylescreated="radGridWrapper_ExcelMLExportStylesCreated" onexcelmlexportrowcreated="radGridWrapper_ExcelMLExportRowCreated" >
                <ExportSettings OpenInNewWindow="true" />
                <MasterTableView AutoGenerateColumns="true" CellSpacing="-1">
                            <ItemTemplate>
                             <h4 style="font-weight:bold;color:Black; width:100%;height:15px"   align="left" > Manpower Summary<asp:Label ID="lblmansummary" runat="server" Visible="false" ></asp:Label></h4>
                                    <telerik:RadGrid ID="grdmanpower" runat="server" 
                                    OnNeedDataSource="RadGrid_NeedDataSource" AutoGenerateColumns="False" 
                                    CellSpacing="1" GridLines="Vertical" Width="100%" AllowSorting="true" Skin="Web20" 
                                    HeaderStyle-HorizontalAlign="Center" HeaderStyle-Font-Underline="true" HeaderStyle-Wrap="false" 
                                    HeaderStyle-Font-Bold="true" HeaderStyle-Font-Names="Arial"  FooterStyle-HorizontalAlign="Right" FooterStyle-Font-Bold="true"
                                    PagerStyle-Wrap="false"  OnItemDataBound="grdmanpower_ItemDataBound"  OnColumnCreated="grdmanpower_ColumnCreated"  >
                                        <ItemStyle Font-Names="Arial"></ItemStyle>
                                        <AlternatingItemStyle Font-Names="Arial" /> 
                                       <MasterTableView AutoGenerateColumns="false" ShowFooter="true" UseAllDataFields="true">
                                        <Columns>
                                            <telerik:GridBoundColumn DataField="Project Name" HeaderText="Project Name"  ItemStyle-Wrap="false" DataFormatString="{0:f1}" UniqueName="Project Name" ></telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="Total Hours Booked (including OT)" HeaderText="Total Hours Booked<br/>(including OT)" DataFormatString="{0:f1}" UniqueName="Total Hours Booked (including OT)" ></telerik:GridBoundColumn>                                            
                                            <telerik:GridBoundColumn DataField="Booked Manpower (including OT,Abs and WO)" HeaderText="Booked Manpower<br/>(including OT,Abs and WO)" UniqueName="Booked Manpower (including OT,Abs and WO)" ItemStyle-Width = "14%" DataFormatString="{0:f1}" ></telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="Present" HeaderText="Present" ItemStyle-Width = "14%" DataFormatString="{0:f1}" UniqueName="Present" ></telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="Abs" HeaderText="Abs" ItemStyle-Width = "14%" DataFormatString="{0:f1}" UniqueName="Abs"></telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="Weekly Off" HeaderText="Weekly Off" ItemStyle-Width = "16%" DataFormatString="{0:f1}" UniqueName="Weekly Off"></telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="Training" HeaderText="Training" ItemStyle-Width = "14%" DataFormatString="{0:f1}" UniqueName="Training"></telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="Abs %" HeaderText="Abs %" ItemStyle-Width = "14%" DataFormatString="{0:f1}" UniqueName="Abs %"></telerik:GridBoundColumn>
                                        </Columns>
                                       </MasterTableView>
                                    </telerik:RadGrid>
                                                          
            </MasterTableView>
        </telerik:RadGrid>

In this excluding the first column i.e. project name i want to display the total for all the other columns.
I tried to use Column created event.
if (e.Column is GridBoundColumn)
            {
                if (col.UniqueName != "Project Name")
                {
                    col.Aggregate = GridAggregateFunction.Sum;
                    col.FooterText = " ";
                    col.HeaderStyle.Width = Unit.Pixel(30);
                    col.ItemStyle.HorizontalAlign = HorizontalAlign.Right;
                }
            }
but this is not working please let me know how i can go about doing this i.e. in any other event like itemdatabound or something please let me know....

7 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 17 Nov 2010, 03:20 PM
Hello Senthil,

More details about how to modify the grid footer(s) or process calculations and visualize them in the footer rows you can find in these online resources:
http://www.telerik.com/help/aspnet-ajax/grdtotalsingridfooters.html
http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/aggregates/defaultcs.aspx

Kind regards,
Pavlina
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Senthil ramna
Top achievements
Rank 1
answered on 18 Nov 2010, 04:54 AM
Thanks about for your reply Pavlina.based on the links you provide i have modified my above code to something like this
<MasterTableView AutoGenerateColumns="false" ShowFooter="true" UseAllDataFields="true" OnDataBinding="MasterTableView_DataBinding">
<Columns>
  <telerik:GridBoundColumn DataField="Project Name" HeaderText="Project Name"  ItemStyle-Wrap="false" DataFormatString="{0:f1}" UniqueName="Project Name" ></telerik:GridBoundColumn>
 <telerik:GridNumericColumn Aggregate="Sum" DataField="Total Hours Booked (including OT)" HeaderText="Total Hours Booked<br/>(including OT)" UniqueName="Total Hours Booked (including OT)"  DataFormatString="{0:f2}"></telerik:GridNumericColumn>
</MasterTableView>
after doing this in the code behind
protected void MasterTableView_DataBinding(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            if (cboProjectgroup.SelectedItem.Text != "Select" && txtdate.Text != "")
            {
                try
                {
                    DataSet dst = new DataSet();
                    dst.Clear();
                    dst = RS.GetTimeSheetMethods(txtdate.Text, cboGL.SelectedValue.ToString(), cboTM.SelectedValue.ToString(), cboProject.SelectedValue.ToString(), cboProjectgroup.SelectedValue.ToString(), working_hours, ot_hours);
                    if (dst.Tables[0] != null)
                    {
                        RadGrid grdmanpower = radGridWrapper.Items[0].FindControl("grdmanpower") as RadGrid;
                        GridNumericColumn totalhours = grdmanpower.MasterTableView.GetColumnSafe("Total Hours Booked (including OT)") as GridNumericColumn;
                        totalhours.FooterAggregateFormatString = totalhours.Aggregate.ToString() + ": {0:f2}";
                    }
                }
                catch (Exception ex)
                {
                    EH.SendException_Mail(ex);
                    Page.ClientScript.RegisterStartupScript(base.GetType(), "Alert", GC.Message(ex.Message.ToString()));
                }
            }
        }
    }
above based on if the data is present in the dataset i am finding the grid and binding the column
i keep getting the below error
Sum is not supported for type "System.Object"  
please let me know what i am doing wrong and please help me out.
0
Pavlina
Telerik team
answered on 18 Nov 2010, 11:15 AM
Hi Senthil,

I tested the setup locally, and it behaved as expected.
If the issue persists, you can open a formal support ticket, and send us a small working project, demonstrating your setup, and the unwanted behavior. We will review it and get back to you with additional information.

Kind regards,
Pavlina
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Senthil ramna
Top achievements
Rank 1
answered on 19 Nov 2010, 05:43 AM
Hey pavlina thanks for the help, what i did was i removed whatever code i had written in itemdata bound event and changed all my bound fields( for which i wanted to get the sum) to numeric fields and wala it stated working.
The only problem i am facing is when i am exporting(in my case i am exporting multiple grids to excel) which is working fine by the way expect for the problem that my footer comes on the Top of data, just below the header.  Is there any way that I can make the footer appear at the end of the rows.
and F.Y.I, am using RadControls for ASPNET AJAX Q1 2009
below is my code
RadGrid radGrid = lbl_txt.Text == "All RadGrids" ? radGridWrapper : (RadGrid)radGridWrapper.Items[0].FindControl(lbl_txt.Text);
  
            if (isExcelExport = true)
            {
                gridcaption = "<b style='color: blue; text-align: left;'>Time Sheets Missing Report</b>";
                if (CheckBox4.Checked == true)
                {
                    gridcaption += "<BR/>" + "<b>Selected Project : </b>" + cboProject.SelectedItem.Text + " " + "|" + " " + "<b>Selected Date : </b> " + txtdate.Text + " " + "|" + " " + "<b>TaskManager Selected :</b>" + cboTM.SelectedItem.Text + " " + "|" + " " + "<b>GroupLead Selected :</b>" + cboGL.SelectedItem.Text;
                }
  
                radGrid.MasterTableView.Caption = gridcaption;
                radGrid.ExportSettings.FileName = "Page1_" + "_for_" + txtdate.Text;
                ConfigureExport(); 
                radGrid.MasterTableView.ExportToExcel();
            }

any help is appreciated.
0
Pavlina
Telerik team
answered on 19 Nov 2010, 04:52 PM
Hello Senthil,

Please examine the following forum thread which elaborates on similar subject and see if it helps:
http://www.telerik.com/community/forums/aspnet-ajax/grid/sum-columns-in-exported-excel.aspx

Regards,
Pavlina
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Senthil ramna
Top achievements
Rank 1
answered on 22 Nov 2010, 05:41 AM

Thanks for the link Pavlina but i am using Excel in HTML format not ExcelIML format.

The thing in my case is the i am able to add or sumup my columns in my page i am getting them to add correctly but when i export i am getting the footer which contains the Total which comes below the header before the data.

I don't understand this as Export to excel is an inbuilt function that you have, so it should export the grid as it is right,  so how is it that the footer is being displayed before the data....

is it because of the item data bound event where i am customizing the footer text to display total is it because of this that the footer is coming before the data in excel when exported...

protected void grid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
       try
        {
          if (e.Item is GridFooterItem)
            {
                GridFooterItem footer = (GridFooterItem)e.Item;
                footer["Project_Name"].Controls.Add(new LiteralControl("<span>Total :</span>"));
                footer["Project_Name"].Style.Add("Text-align", "right");
            }
        }
        catch (Exception ex)
        {
            EH.SendException_Mail(ex);
            Page.ClientScript.RegisterStartupScript(base.GetType(), "Alert", GC.Message(ex.Message.ToString()));
        }
    }

please let me know what the problem is...
0
Pavlina
Telerik team
answered on 24 Nov 2010, 04:13 PM
Hello Senthil,

Could you please open a formal support ticket and send us small runnable application which demonstrates the issue. We will test it locally and advise you further.

Looking forward for your reply.

Greetings,
Pavlina
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Senthil ramna
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Senthil ramna
Top achievements
Rank 1
Share this question
or