Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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:
 
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 25-Apr-12 1:02am
Edited 25-Apr-12 2:10am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CHill60 195
1 Zoltán Zörgő 175
2 Richard Deeming 170
3 Richard MacCutchan 160
4 Peter Leow 145
0 Sergey Alexandrovich Kryukov 9,328
1 OriginalGriff 6,831
2 Peter Leow 4,477
3 Zoltán Zörgő 3,984
4 Richard MacCutchan 2,832


Advertise | Privacy | Mobile
Web02 | 2.8.150129.1 | Last Updated 6 Dec 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100