User364607740 posted
How can I do cell merge for common values in the first column only of DataTable? In this solution, it does the cell merge for every columns of the DataTable.
protected void StdGrid_DataBound(object sender, EventArgs e)
{
for (int i = StdGrid.Rows.Count - 1; i > 0; i--)
{
GridViewRow row = StdGrid.Rows[i];
GridViewRow previousRow = StdGrid.Rows[i - 1];
for (int j = 0; j < row.Cells.Count; j++)
{
if (row.Cells[j].Text == previousRow.Cells[j].Text)
{
if (previousRow.Cells[j].RowSpan == 0)
{
if (row.Cells[j].RowSpan == 0)
{
previousRow.Cells[j].RowSpan += 2;
}
else
{
previousRow.Cells[j].RowSpan = row.Cells[j].RowSpan + 1;
}
row.Cells[j].Visible = false;
}
}
}
}
}
Student Name Subjects Marks
S1 ECO 81
S1 GEO 95
S1 FIN 98
S2 ECO 98
S2 FIN 98
-------------------------------------------------------
-------------------------------------------------------
SAMPLE OUTPUT
Student Name Subjects Marks
ECO 81
S1 GEO 95
FIN 98
-------------------------------------------
ECO 98
S2 FIN 98
-------------------------------------------