gridview合併同一列相同內容的單元格

             if (GridView1.Rows.Count > 0)
            {
                string nowDepart = GridView1.Rows[0].Cells[0].Text;
                int startL = 0;

                for (int i = 1; i <= GridView1.Rows.Count; i++)
                {
                    if (i == GridView1.Rows.Count || GridView1.Rows[i].Cells[0].Text != nowDepart)
                    {
                        GridView1.Rows[startL].Cells[0].RowSpan = i - startL;
                        for (int j = startL + 1; j < i; j++)
                        {
                            GridView1.Rows[j].Cells[0].Visible = false;
                        }
                        if (i < GridView1.Rows.Count)
                        {
                            nowDepart = GridView1.Rows[i].Cells[0].Text;
                            startL = i;
                        }
                    }
                }
            }

發佈了27 篇原創文章 · 獲贊 4 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章