2012年11月2日 星期五
GridView合併欄位
//GridView合併欄位 GridView加入OnPreRender事件
i =Rows ;j = Columns; Cells =
protected void grid_view_PreRender(object sender, EventArgs e)
{
for (int j = 2; j < 3; j++)
{
int i = 1;
foreach (GridViewRow wkItem in grid_view.Rows)
{
if (Convert.ToInt32(wkItem.RowIndex) == 0)
{
wkItem.Cells[j].RowSpan = 1;
wkItem.Cells[j+1].RowSpan = 1;
}
else
{
//if (wkItem.Cells[j].Text.Trim() == grid_view.Rows[Convert.ToInt32(wkItem.RowIndex) - i].Cells[j].Text.Trim())
if (((Label)wkItem.FindControl("lblGUAR_NM")).Text.Trim() == ((Label)grid_view.Rows[Convert.ToInt32(wkItem.RowIndex) - i].FindControl("lblGUAR_NM")).Text.Trim())
{
grid_view.Rows[Convert.ToInt32(wkItem.RowIndex) - i].Cells[j].RowSpan += 1;
grid_view.Rows[Convert.ToInt32(wkItem.RowIndex) - i].Cells[j+1].RowSpan += 1;
i = i + 1;
wkItem.Cells[j].Visible = false;
wkItem.Cells[j+1].Visible = false;
}
else
{
grid_view.Rows[Convert.ToInt32(wkItem.RowIndex)].Cells[j].RowSpan = 1;
grid_view.Rows[Convert.ToInt32(wkItem.RowIndex)].Cells[j+1].RowSpan = 1;
i = 1;
}
}
}
}
}
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言