Reputation: 783
I have a gridview with the first column merged. I used the following code in databound.
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 - 3; cellCount++)
{
if (gvRow.Cells[cellCount].Text == gvPreviousRow.Cells[cellCount].Text)
{
if (gvPreviousRow.Cells[cellCount].RowSpan < 2)
{
gvRow.Cells[cellCount].RowSpan = 2;
}
else
{
gvRow.Cells[cellCount].RowSpan = gvPreviousRow.Cells[cellCount].RowSpan + 1;
}
gvPreviousRow.Cells[cellCount].Visible = false;
}
}
}
I want to merge the last column according to first column.
I tried with the following code. But it did not work.
for (int t = 0; t < GridView1.Rows.Count; t++)
{
GridView1.Rows[t].Cells[3].RowSpan = GridView1.Rows[t].Cells[0].RowSpan;
}
Can anyone help me doing this?
Thanks in advance
Upvotes: 0
Views: 1296
Reputation: 4727
As i said in the comment, if you want the 4th row to be merged with the 3rd you should set the merge property on the 3rd column.
for (int t = 0; t < GridView1.Rows.Count; t++)
{
GridView1.Rows[t].Cells[2].RowSpan = GridView1.Rows[t].Cells[0].RowSpan;
}
Upvotes: 1