如何在gridview中合并两个单元格 [英] How to merge two cells in gridview

查看:200
本文介绍了如何在gridview中合并两个单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在gridview中有一些数据,格式如下:

I have some data in a gridview, in this format:

A     B
1     
2     adeel
3
4     sml

现在我想将行与B列下的空单元格。我将如何做到这一点?

Now I want to merge the row with the empty cell under the B column. How would I do this?

推荐答案

要合并同一列中的行,您可以使用如下代码: p>

to merge the rows in a same column, you choule use the code like this :

public static void GroupRows(GridView GridView1, int cellNum)
{
    int i = 0, rowSpanNum = 1;
    while (i < GridView1.Rows.Count - 1)
    {
        GridViewRow gvr = GridView1.Rows[i];
        for (++i; i < GridView1.Rows.Count; i++)
        {
            GridViewRow gvrNext = GridView1.Rows[i];
            if (gvr.Cells[cellNum].Text != "" && gvrNext.Cells[cellNum].Text == "") ///here, chould change the term to suit other conditions, such like merging the same content of different rows in a same column.
            {
                gvrNext.Cells[cellNum].Visible = false;
                rowSpanNum++;
            }
            else
            {
                gvr.Cells[cellNum].RowSpan = rowSpanNum;
                rowSpanNum = 1;
                break;
            } 
            if (i == GridView1.Rows.Count - 1)
            {
                gvr.Cells[cellNum].RowSpan = rowSpanNum;
            }
        }
    }
}

这篇关于如何在gridview中合并两个单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆