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

Aggregate at the Footer

4 Answers 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
L
Top achievements
Rank 1
L asked on 12 Nov 2008, 07:04 AM
hi

I have the aggregate at the footer of the gird. It work well if you have rows of records.

But i have this situation that at times i do not have any row of record and when i view the page if gave me an error:

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 16:             daClasscode.Fill(dtClasscodeA)
Line 17:             RadGrid1.DataSource = dtClasscodeA
Line 18: RadGrid1.DataBind()Line 19:         End If

It is trying to sum a column when there is not a single row of record. How do I overcome this? Thanks

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 12 Nov 2008, 10:11 AM
Hello Lui Nai Wah,

A suggestion is to check for the row count in the grid using the code and set the aggregate property accordingly. You can check for the row count as:
cs:
if(RadGrid1.MasterTableView.Items.Count > 0) 
   { 
     // set the aggregates here
   } 

Also you can use the Advanced DataBinding Techniques, detailed information of which is given in the following link.
Advanced Data-binding (using NeedDataSource event)

Thanks
Princy.
0
Iana Tsolova
Telerik team
answered on 12 Nov 2008, 04:16 PM
Hi Lui,

I followed your scenario but the footer aggregate worked as expected on my end. Please find the attached sample and let me know if I missed something and what differs in your case.

Looking forward your reply,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
L
Top achievements
Rank 1
answered on 13 Nov 2008, 02:18 AM
hi

It seems that your example has a row in the Datatable:

if (Session["Data"] == null)
            {
                DataTable table = new DataTable();
                table.Columns.Add("ID", typeof(Int32));
                table.Columns.Add("Items");
                for (int i = 1; i <= 0; i++)
                {
                    table.Rows.Add(i, "Item" + i.ToString());
                }
                Session["Data"] = table;
            }
            return (DataTable)Session["Data"];

but in my case my Datatable is empty. Thanks
0
Accepted
Princy
Top achievements
Rank 2
answered on 13 Nov 2008, 04:57 AM
Hello Lui Nai Wah,

I noticed in your for loop that 'i'  is initialised to 1 and then you check for i<=0, due to which the row does not get added up since the for loop is never entered.

Thanks
Princy.
Tags
Grid
Asked by
L
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Iana Tsolova
Telerik team
L
Top achievements
Rank 1
Share this question
or