Click here to Skip to main content
15,895,740 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
here is my code

C#
protected void grdTesters_RowDataBound(object sender, GridViewRowEventArgs e)
   {
       int sum;

       if (e.Row.RowType == DataControlRowType.DataRow)
       {
           sum = sum + Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "ExecutionTime"));
       }
       if (e.Row.RowType == DataControlRowType.Footer)
       {
           Label obj = (Label)e.Row.FindControl("Sum");
           obj.Text = Convert.ToString(sum);
       }



m getting error like

Error Use of unassigned local variable 'sum'		
Posted

Its too simple you just need to assign your local variable sum some value
like int sum=0;
 
Share this answer
 
Dear Friend,

You have not assigned any value to sum while initializing i.e.,

int sum=0;


I hope this will solve your problem.

Please don't forget to mark this as your answer if it helps you out.

Thanks
 
Share this answer
 
Comments
ythisbug 18-Feb-12 3:49am    
bro i tried with int sum=0; but its working..but in total colum it showing 0 as total..
Varun Sareen 18-Feb-12 4:07am    
Friend, Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "ExecutionTime") may not be giving any value and as sum=0 so it is displaying result as 0. Please check
hey
you used sum variable without assign any value to it so
assign 0 value to sum variable like
int sum=0;
 
Share this answer
 
try

int sum=0

and when total column = 0. please declaration sum variable out of method

Please tell me if it's work
 
Share this answer
 
v3
You can use Compute() Method of datatable to get the column sum like.

string total = string.Format("{0:0.00}", Convert.ToDouble(datatable.Compute("sum(ExecutionTime)", null)));


Here datatable is the datasourch of your gridview.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900