프로그래밍/ASP.NET
[ASP.NET] GridView rowspan Cell merge
쇠주는참이슬
2012. 5. 26. 14:15
protected void getGridMerge(GridView grid)
{
int RowSpan = 1;
int ColCNT = 1; //병합을 해야하는 컬럼 index
for (int j = 0; j < grid.Columns.Count - 1; j++)
{
if (grid.Columns[j].Visible && j == ColCNT)
{
for (int i = grid.Rows.Count - 1; i > 0; i--)//아이템 검색
{
System.Web.UI.Control bfControl = grid.Rows[i - 1].Cells[j].Controls[1];
System.Web.UI.Control afControl = grid.Rows[i].Cells[j].Controls[1];
System.Web.UI.WebControls.Label bflbl = bfControl as System.Web.UI.WebControls.Label;
System.Web.UI.WebControls.Label aflbl = afControl as System.Web.UI.WebControls.Label;
if (bflbl.Text == aflbl.Text)
{
RowSpan++;
grid.Rows[i - 1].Cells[j].RowSpan = RowSpan; //RowSpan
// GridView1.Rows[i - 1].Cells[1].BackColor = Color.Gainsboro; //배경색
grid.Rows[i].Cells[j].Visible = false;
grid.Rows[i].Cells[j].Controls[1].Visible = false;
}
else
{ RowSpan = 1; }
}
}
}
}