How To Merge GridView Cells in ASP.NET

Place the following code, or some variation thereof depending on your requirements,
in the RowBinding event of your GridView:

if (e.Row.DataItemIndex % 2 = 0)
{
	e.Row.Cells[0].RowSpan = 2;
	e.Row.Cells[1].RowSpan = 2;
}

Remove the extra cells created due to row span for odd rows

if (e.Row.DataItemIndex % 2 = 1)
{
	e.Row.Cells.RemoveAt[0];
	e.Row.Cells.RemoveAt[0];
	e.Row.Cells[1].HorizontalAlign = HorizontalAlign.Center;
}

Please do not post any spam link in the comment box😊

إرسال تعليق (0)
أحدث أقدم