Click here to Skip to main content
15,896,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

This code does not works for merged rows.I want to get the Serial number for Merged rows. For example there are 3 colums C1(seria no),C2,C3. For one value of C2 there is multiple values of C3. Therefore I have merged C2 for same values. But I am not able to get serial number for C2.

I am using below code for Merging the C2 for same values:

C#
protected void GrdReportingDetails_PreRender(object sender, EventArgs e)
    {
        GridDecorator.MergeRows(GrdReportingDetails);
    }
public class GridDecorator
{
    public static void MergeRows(GridView gridView)
    {
        for (int rowIndex = gridView.Rows.Count - 2; rowIndex >= 0; rowIndex--)
        {
            GridViewRow row = gridView.Rows[rowIndex];
            GridViewRow previousRow = gridView.Rows[rowIndex + 1];

            for (int i = 1; i < row.Cells.Count; i++)
            {
                if (row.Cells[i].Text == previousRow.Cells[i].Text)
                {
                    row.Cells[i].RowSpan = previousRow.Cells[i].RowSpan < 2 ? 2 :
                                           previousRow.Cells[i].RowSpan + 1;
                    previousRow.Cells[i].Visible = false;
                }
            }
        }
    }
}
Posted
Updated 25-Apr-12 1:10am
v2

1 solution

Hi,
I didn't get any C# code for the issue. But if the data is coming from SQL Stored Proc, we can get the readymade serial number using a one liner in the stored proc.

SELECT
dense_rank() OVER (ORDER BY R.Request_Id) as SrNo,
R.Request_Id,
R.Request_Type,
R.Client_Name,
R.Request_Rec_On,
R.Request_Due_On,
R.Success_Flag
From REQ_Request R.

dense_rank() OVER (ORDER BY R.Request_Id) will solve the query and you may just display the Stored proc output in the gridview.
 
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