Click here to Skip to main content
15,070,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
for (int rowIndex = GVDCNoConfirm.Rows.Count - 2; rowIndex >= 0; rowIndex--)
    {
        GridViewRow currentRow = GVDCNoConfirm.Rows[rowIndex];
        GridViewRow previousRow = GVDCNoConfirm.Rows[rowIndex + 1];

        for (int i = 0; i < currentRow.Cells.Count; i++)
        {
            if (currentRow.Cells[i].Text == previousRow.Cells[i].Text)
            {
                if (previousRow.Cells[i].RowSpan < 2)
                    currentRow.Cells[i].RowSpan = 2;
                else
                    currentRow.Cells[i].RowSpan = previousRow.Cells[i].RowSpan + 1;
                previousRow.Cells[i].Visible = false;
            }
            if (row.Cells[6].Text == previousRow.Cells[6].Text)
            {
                            float currentvalue = 0;
                             currentvalue = Convert.ToSingle(row.Cells[5].Text);
                             float previousvalue = currentvalue + Convert.ToSingle(previousRow.Cells[5].Text);
                             row.Cells[5].Text = Convert.ToString(previousvalue);
                            previousRow.Cells[j].Visible = false;
                        }

        }
    }

I have this code in RowDataBound for merging gridview rows. Its working fine But
C#
sno    name    amount   dcno
 1     xxx     5000     888
               2500
               1000     1001
 2     yyy     5250     1002
               2000      555
               1250      555

In this grid I want to sum (5000+2500)=7500 i.e same dcno 888 and like that (2000+1250)=3250 i.e same dcno 555
So I need Out put like
C#
sno    name   amount   dcno
 1     xxx     7500     888
               1000     1001
 2     yyy     5250    1002
               3250     555
Posted
Updated 27-Sep-14 2:32am
v3
Comments
aarif moh shaikh 27-Sep-14 8:52am
   
Not Getting your Actual Problem ... please Describe more...
santhu888 29-Sep-14 0:44am
   
actuallly we are merging gridview cell . In that we have some same dcno rows.
so i have to sum those rows amount(condition same dcno rows). please suggest me.

1 solution

If you're talking about "balance query", have a look here: Running totals in SQL Server queries[^]

More on Google[^]!
   

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