Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i have a gridview...it contain 3 column date, name and total...i need to calculate the sum of the total and it will display on label...if total is 10,20,30 then label should display 60...please help
Posted
Updated 6-Oct-12 16:17pm
v2
Comments
vrehor 6-Oct-12 9:53am    
Do you use binding to Items property of ListView?
If yes, then use same binding for Label.Content property and use IValuConverter to count total.
[no name] 8-Oct-12 0:25am    
Is it WinForm?
ANOOP CL NAIR 8-Oct-12 2:11am    
thanks for ur replay it is in web application...

C#
int Cnt;
For(int i=0;i<gridview1.rows.count-1;i++)>
{
Cnt+=Convert.ToDouble(Gridview1.Rows[i].Cells[2].Text);
}
lblTotal.Text=Cnt.toString();
 
Share this answer
 
v2
Comments
ANOOP CL NAIR 6-Oct-12 22:11pm    
i wrote same code in load page....its showing error in Row(i)....Non-invocable member 'System.Web.UI.WebControls.GridView.Rows' cannot be used like a method.

int Cnt;
for (int i = 0; i < GridView9.Rows.Count - 1; i++)
{
Cnt += Convert.ToDouble(GridView9.Rows(i).Cells(2).Text);
}
Label32.Text = Cnt.ToString();
[no name] 8-Oct-12 0:27am    
For specifying an index you should write it between "[]" not "()".
Devang Vaja 8-Oct-12 0:30am    
i have improved sollution
Just iterate through the loop of DataGridViewRows

C#
private void button1_Click(object sender, EventArgs e)
       {
           decimal total = 0;

           foreach (DataGridViewRow row in dataGridView1.Rows)
           {
               if (!row.IsNewRow && row.Cells["Total"].Value != null)
               {
                   total += (decimal)row.Cells["Total"].Value;
               }
           }
             
            label1.Text = total.ToString("N2");
       }
 
Share this answer
 
Comments
shaikh-adil 7-Oct-12 0:56am    
hey bro anoop. can you give me some example or article where i can have filter in grid view i am a learner.
for example i have a data column in grid view so i want to filter the coulmn but months and years
i am using windows form
shaikh-adil 7-Oct-12 0:57am    
+5
Manoj Kumar Choubey 8-Oct-12 0:37am    
+5
Hi,

If you are fetching data through the StoredProcedure then you can simply add one more row in the return table with total of all the values. And this would be easier for you to calculate. or even you can return multiple tables so the 2nd table will contain summation of your total.

Hope it works fine for you
Thanks.
 
Share this answer
 

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