Click here to Skip to main content
15,881,823 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a two gridview.Have column in both are,

first:

code Tax% TaxAmount
1 3 0.73
2 4 1.3
3 3 0.92


Second:

Tax% TaxAmount
3 1.65
4 1.3

as per above mentioned when we have same Tax% in 1st grid,it will add and shows the sum in another grid.

so let me know how to do this please...
please help sumbody..
Posted
Updated 7-Oct-12 20:55pm
v3
Comments
Shivani Dash 2-Oct-12 2:39am    
Can nebody help me plz...
Santhosh Kumar Jayaraman 8-Oct-12 3:24am    
You got the solution?

This is not an exact answer to your question, however, it might just help you get started - CodeProject Frequently Asked Questions Series 1: The ASP.NET GridView[^].
 
Share this answer
 
try this

C#
DataTable dt = new DataTable();
           DataRow dr = dt.NewRow();
           dt.Columns.Add("code", typeof(int));
           dt.Columns.Add("Tax", typeof(int));
           dt.Columns.Add("Amount", typeof(decimal));
           dr["code"] = 1;
           dr["tax"] = 3;
           dr["Amount"] = 0.73;
           dt.Rows.Add(dr);
           DataRow dr1 = dt.NewRow();
           dr1["code"] = 2;
           dr1["tax"] =4;
           dr1["Amount"] =1.3;
           dt.Rows.Add(dr1);
           DataRow dr2 = dt.NewRow();
           dr2["code"] = 3;
           dr2["tax"] = 3;
           dr2["Amount"] = 0.92;
           dt.Rows.Add(dr2);
           DataTable dt1 = new DataTable();

           dt1.Columns.Add("Tax", typeof(int));
           dt1.Columns.Add("TotalAmount", typeof(decimal));

           var query = from row in dt.AsEnumerable()
                       group row by row.Field<int>("Tax") into grp
                       select new
                       {
                           tax = grp.Key,
                           sum = grp.Sum(r => r.Field<decimal>("Amount"))
                       };
           foreach (var grp in query)
           {
               DataRow row = dt1.NewRow();
               row["Tax"] = grp.tax;
               row["TotalAmount"] = grp.sum;
               dt1.Rows.Add(row);
           }
 
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