.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Imran Ghani
Sohaib Khalid

Home >> Code Snippets >> DataGrid >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

How to merge the columns of Gridview in asp.net

Posted By:Brijesh Kumar       Posted Date: March 15, 2011    Points: 40    Category: DataGrid    URL: http://www.dotnetspark.com  

This article refer for the merge the columns of GridView in asp.net c#

Write this code on Gridview1's DataBound event:--
 for (int rowIndex = GridView1.Rows.Count - 2; rowIndex >= 0; rowIndex--)
            GridViewRow gvRow = GridView1.Rows[rowIndex];
            GridViewRow gvPreviousRow = GridView1.Rows[rowIndex + 1];
            for (int cellCount = 0; cellCount < gvRow.Cells.Count; cellCount++)
                if (gvRow.Cells[cellCount].Text == gvPreviousRow.Cells[cellCount].Text)
                    if (gvPreviousRow.Cells[cellCount].RowSpan < 2)
                        gvRow.Cells[cellCount].RowSpan = 2;
                        gvRow.Cells[cellCount].RowSpan = gvPreviousRow.Cells[cellCount].RowSpan + 1;
                    gvPreviousRow.Cells[cellCount].Visible = false;


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend