玄铁剑

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

合并DataGrid相同的行

Posted on 2006-12-20 21:39 玄铁剑 阅读(432) 评论(0)  编辑 收藏 引用 所属分类: asp.net

    private void MergeRows(DataGrid grid)
    {
        int row, icur, ispan;
        int icol = grid.Columns.Count - 1;
        int irow_count = grid.Items.Count - 1;
        string strtmp;

        for (int col = 0; col <= icol; col++)
        {
            if (grid.Columns[col].Visible == false)
                continue;
            ispan = 1;
            row = 0;
            icur = 0;
            while (row <= irow)
            {
                strtmp = grid.Items[icur].Cells[col].Text.ToString();
                row += 1;
                if (row <= irow)
                {
                    if (grid.Items[row].Cells[col].Text.ToString().Equals(strtmp))
                    {
                        ispan += 1;
                        grid.Items[icur].Cells[col].RowSpan = ispan;
                        grid.Items[row].Cells[col].Visible = false;
                    }
                    else
                    {
                        ispan = 1;
                        icur = row;
                    }
                }
            }
        }
    } 

只有注册用户登录后才能发表评论。