问题
I have some data in a gridview, in this format:
A B
1
2 adeel
3
4 sml
Now I want to merge the row with the empty cell under the B column. How would I do this?
回答1:
to merge the rows in a same column, you choule use the code like this :
public static void GroupRows(GridView GridView1, int cellNum)
{
int i = 0, rowSpanNum = 1;
while (i < GridView1.Rows.Count - 1)
{
GridViewRow gvr = GridView1.Rows[i];
for (++i; i < GridView1.Rows.Count; i++)
{
GridViewRow gvrNext = GridView1.Rows[i];
if (gvr.Cells[cellNum].Text != "" && gvrNext.Cells[cellNum].Text == "") ///here, chould change the term to suit other conditions, such like merging the same content of different rows in a same column.
{
gvrNext.Cells[cellNum].Visible = false;
rowSpanNum++;
}
else
{
gvr.Cells[cellNum].RowSpan = rowSpanNum;
rowSpanNum = 1;
break;
}
if (i == GridView1.Rows.Count - 1)
{
gvr.Cells[cellNum].RowSpan = rowSpanNum;
}
}
}
}
回答2:
You can use "layout:coloumnSpan" or "layout:rowSpan" to make an object "merge" over two columns or rows as required. Simply set the value to 2 for it to merge over 2 rows/columns.
来源:https://stackoverflow.com/questions/12512771/how-to-merge-two-cells-in-gridview