Click here to Skip to main content
16,004,782 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Sno    Date   Partyname   Meattye   Weight  Rate   Total    DCNO      
 1    26/10     A           Chicken  12      150    1800     1546      
 2    26/10     A           Mutton   10      150    1500     1546 

      
 3    26/10     A           Keema    5       100     500     1547 
     
 4    26/10     C           Chicken  12      150    1800     1548 
 
 5    26/10     D           Chicken  12      150    1800     1549 
 6    26/10     D           Beef     10      150    1500     1549      


My desired O/P is( Only merge and add #Total Feild based on  DCNO)


 Sno    Date   Partyname   Meattye   Weight  Rate   Total    DCNO      
 1    26/10     A           Chicken  12      150     3300    1546      
 2    26/10     A           Mutton   10      150             1546 
      
 3    26/10     A           Keema    5       100     500     1547
      
 4    26/10     C           Chicken  12      150    1800     1548 
 
 5    26/10     D           Chicken  12      150             1549 
 6    26/10     D           Beef     10      150    3300     1549 





Here is my code
C#
protected void GVDCNoConfirm_RowDataBound(object sender, GridViewRowEventArgs e)
   {
       var thisRow = e.Row;
       if (e.Row.RowType == DataControlRowType.DataRow)
       {



         for (int rowIndex = GVDCNoConfirm.Rows.Count - 2; rowIndex >= 0; rowIndex--)
           {

               GridViewRow gvRow = GVDCNoConfirm.Rows[rowIndex];
               GridViewRow gvPreviousRow = GVDCNoConfirm.Rows[rowIndex + 1];



               for (int cellCount = 8; cellCount < gvRow.Cells.Count;
                                                             cellCount++)
               {


                   if (gvRow.Cells[cellCount].Text ==
                                          gvPreviousRow.Cells[cellCount].Text)
                   {


                       if (gvPreviousRow.Cells[cellCount].RowSpan < 2)
                       {
                           float currentvalue = 0;
                           currentvalue = Convert.ToSingle(gvRow.Cells[7].Text);
                           gvRow.Cells[7].Text = Convert.ToString(currentvalue + Convert.ToSingle(gvPreviousRow.Cells[7].Text));
                           gvRow.Cells[cellCount].RowSpan = 2;
                           gvRow.Cells[7].RowSpan =2;



                       }
                       else
                       {
                           gvRow.Cells[cellCount].RowSpan =
                          gvPreviousRow.Cells[cellCount].RowSpan + 1;
                           gvRow.Cells[7].RowSpan =
                         gvPreviousRow.Cells[7].RowSpan + 1;

                       }
                       gvPreviousRow.Cells[cellCount].Visible = false;
                       gvPreviousRow.Cells[7].Visible = false;



                   }
               }



           }




       }
   }
Posted
Updated 2-Nov-14 22:53pm
v4
Comments
[no name] 3-Nov-14 4:33am    
Why dont you do that from DB side ?
Bhagavan Raju M 3-Nov-14 4:45am    
I have to merge rows in gridview . How its possible to do with DB?
[no name] 3-Nov-14 5:00am    
Fetch the data in your desired format from the database and bind it directly to gridview.
This is what i meant.
Sinisa Hajnal 3-Nov-14 4:33am    
Use your database query to sum those values before they are bound (that is, your query should do summing and grouping, databases are good with such things)
Bhagavan Raju M 3-Nov-14 4:45am    
I have to merge rows in gridview . How its possible to do with DB?

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