玄铁剑

成功的途径:抄,创造,研究,发明...
posts - 128, comments - 42, trackbacks - 0, articles - 174

GridView行合並

Posted on 2007-09-03 14:00 玄铁剑 阅读(856) 评论(1)  编辑 收藏 引用 所属分类: asp.net

    public static void GroupRows(GridView gvMerge, int cellNum)
    {
        int i = 0, rowSpanNum = 1;
        while (i < gvMerge.Rows.Count - 1)
        {
            GridViewRow gvr = gvMerge.Rows[i];

            for (++i; i < gvMerge.Rows.Count; i++)
            {
                GridViewRow gvrNext = gvMerge.Rows[i];
                if (gvr.Cells[cellNum].Text == gvrNext.Cells[cellNum].Text)
                {
                    gvrNext.Cells[cellNum].Visible = false;
                    rowSpanNum++;
                }
                else
                {
                    gvr.Cells[cellNum].RowSpan = rowSpanNum;
                    rowSpanNum = 1;
                    break;
                }

                if (i == gvMerge.Rows.Count - 1)
                {
                    gvr.Cells[cellNum].RowSpan = rowSpanNum;
                }
            }
        }
    }

Feedback

# re: GridView行合並  回复  更多评论   

2010-03-24 20:06 by 梁飞
不错!!!就是缺少注释!!
只有注册用户登录后才能发表评论。