티스토리 뷰

프로그래밍/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; }



                    }

                }

            }

        }
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함