PreRender是在頁面呈現之前去觸發的所以選擇寫在GridView1_PreRender。
01.
protected
void
GridView1_PreRender1(
object
sender, EventArgs e)
02.
{
03.
int
i = 1;
04.
foreach
(GridViewRow gvItem
in
GridView1.Rows)
05.
{
06.
if
(gvItem.RowIndex != 0)
07.
{
08.
//比對如果名稱如果相同就合併(RowSpan+1)
09.
if
(gvItem.Cells[0].Text.Trim() == GridView1.Rows[(gvItem.RowIndex - i)].Cells[0].Text.Trim())
10.
{
11.
GridView1.Rows[(gvItem.RowIndex - i)].Cells[0].RowSpan += 1;
12.
gvItem.Cells[0].Visible =
false
;
13.
i = i + 1;
14.
}
15.
else
16.
{
17.
GridView1.Rows[(gvItem.RowIndex)].Cells[0].RowSpan += 1;
18.
i = 1;
19.
}
20.
}
21.
else
22.
{
23.
gvItem.Cells[0].RowSpan = 1;
24.
}
25.
}
26.
}
結果:
沒有留言:
張貼留言