Thursday, July 30, 2009

merge cell of same data in grid view

public static void MergeRows(GridView gridView)
{
for (int rowIndex = 0; rowIndex <= gridView.Rows.Count - 1; rowIndex++)
{
GridViewRow row = gridView.Rows[rowIndex];

for (int i = 2; i {
int j = 1;
for (int z = i+1; z < row.Cells.Count ; z++)
{
if (row.Cells[i].Text == row.Cells[z].Text)
{
j++;
}
else
{
break;
}
}
row.Cells[i].ColumnSpan = j;
if (j > 1)
{
for (int k = 1; k <= j - 1; k++)
{
i++;
row.Cells[i].Visible = false;

}

}
}
}

}

No comments: