Click here to Skip to main content
15,905,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to add the value of 2 rows of a datagridview and the result will shown in a textbox...?

suppose have a datagridview of 2 column named "Productname" and "Price".i have two product(pen,paper) n two price(25.75,68).I need the result of (25.75+68) in a textbox with rounded value as 94.00.
Posted
Comments
Sangramsingh Pawar 7-Sep-12 3:23am    
In which type you wnt to do this in web or in windows?
Shivani Dash 7-Sep-12 3:25am    
windows..

try to do this way :
C#
double[] price = new[] { 25.75, 68 };
            double sum = 0;
            for (int i = 0; i < 2; i++)
            {
                sum +=Math.Round(price[i]);
            }

            Console.WriteLine(sum);
            Console.ReadLine();
 
Share this answer
 
u can use datatable compute method like below

totalprice= dtproduct.Compute("SUM(Price)", String.Empty).ToString



then assign the value of totalprise to your desiered textbox , but u can only do it , if u have only 2 rows in datatable , if u want to sum on specific columns then there is another way

Thanks
 
Share this answer
 
v2
Comments
Shivani Dash 7-Sep-12 3:43am    
ya ur right ...i dnt hv only 2 columns....it can b many...

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