In this article write the code to merge column & cells in same data in cells. I am described how to merge cells in Gridview in ASP.NET . In this article I am add OnRowDataBound Event of gridview and use RowSpan of cells.
In this article I am connecting with sql
database & in a table I have some columns like college description, college name with branch wise..
both of colleges have many branches so I merge college name Like this
on Aspx page
In aspx page write Gridview Control then add SqldataSource . Configure database with collge table
and fill grid view. All data show in gridview. Add event in gridview OnRowDataBound="GridView1_RowDataBound"
In aspx.cs page write this code
protected void GridView1_RowDataBound(object
sender, GridViewRowEventArgs e)
(e.Row.RowType == DataControlRowType.DataRow)
//We're only interested in Rows that contain
reference to the data used to databound the row
drv = ((DataRowView)e.Row.DataItem);
(previousCat == drv["Collegename"].ToString())
it's the same category as the previous one
(GridView1.Rows[firstRow].Cells.RowSpan == 0)
GridView1.Rows[firstRow].Cells.RowSpan = 2;
GridView1.Rows[firstRow].Cells.RowSpan += 1;
else //It's a new category
the vertical alignment to top
e.Row.VerticalAlign = VerticalAlign.Top;
the category in memory
previousCat = drv["Collegename "].ToString();
firstRow = e.Row.RowIndex;
Then you run your page & Look like Merger
data in a Gridview
In this article I have tried to solve the problem to merge repeat columns in gridview. Hope fully it helps someone.