Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to merge cells in asp.net if i have duplicate record in cell
i am using this code but after merging data is showing outside of grid i used paging also
code is here
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 = 0; 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;
}
}
}
}
}

//Merging cell
protected void gvbenefit_PreRender(object sender, EventArgs e)
{
GridDecorator.MergeRows(gvbenefit);

}


Claim ID



Benefit Type

Diabetic Supplier








--------------------------------------------------------------------------------








Billed Procedures

Claim Number ID

Dos

Procedure Code

Modifier

Units

Bill Amount

Paid Amount



A4253

1234E1231121

1

1

A

1

12000

12000











Sub Total

5

64000

69000











Sub Total

8

52597

53701









Sub Total

8

125476

81478





Sub Total

1

12000

12000
Posted
Updated 25-Mar-12 19:23pm
v2

I found this link in code project. Maybe this might help you.

Eliminating Duplicate rows in Gridview.[^]

I have a few thoughts that may help as I don't know all the specifics, but let me know if any of this points you in the proper direction.

1. What do you consider duplicate data? This question should prompt you to start thinking along the lines of what constitutes a duplicate such that you can find a remedy to your situation.

2. Before calling this function can you organize the data and remove duplicates before calling it? As a thought what about placing the data in a collection and try to see if you can find duplicates by iterating through all the collection. Not sure if that is a good idea because depending upon quantity of data it may be a bad idea.

3. As I have mentioned before I don't know the specifics, but I was faced in a situation similar to this (again I don't know your specifics). What I did to remedy my duplicates was to take care of it at the database level up creating multiple queries to merge 3 tables into one and remove all duplicates if any.

I hope these thoughts help. Don't give up :). Keep on programming!
 
Share this answer
 
Try this,

public static void GridView_Row_Merger(GridView gridView)
    {
        for (int rowIndex = gridView.Rows.Count - 2; rowIndex >= 0; rowIndex--)
        {
            GridViewRow currentRow = gridView.Rows[rowIndex];
            GridViewRow previousRow = gridView.Rows[rowIndex + 1];

            for (int i = 0; i < currentRow.Cells.Count; i++)
            {
                if (currentRow.Cells[1].Text == previousRow.Cells[1].Text)
                {
                    if (previousRow.Cells[1].RowSpan < 2)
                        currentRow.Cells[1].RowSpan = 2;
                    else
                        currentRow.Cells[1].RowSpan = previousRow.Cells[1].RowSpan + 1;
                    previousRow.Cells[1].Visible = false;
                    if (currentRow.Cells[2].Text == previousRow.Cells[2].Text)
                    {
                        if (previousRow.Cells[2].RowSpan < 2)
                            currentRow.Cells[2].RowSpan = 2;
                        else
                            currentRow.Cells[2].RowSpan = previousRow.Cells[2].RowSpan + 1;
                        previousRow.Cells[2].Visible = false;
                    }
                }

            }
        }
    }
 
Share this answer
 
Comments
md.nezamuddin1983 26-Mar-12 1:25am    
i used this code also but still my all griddata showing outside of grid anybody help me

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