【问题标题】:How to merge two cells in gridview如何在gridview中合并两个单元格
【发布时间】:2012-09-20 12:38:55
【问题描述】:

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

A     B
1     
2     adeel
3
4     sml

现在我想将该行与 B 列下的空单元格合并。我该怎么做?

【问题讨论】:

    标签: gridview merge


    【解决方案1】:

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

    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;
                }
            }
        }
    }
    

    【讨论】:

      【解决方案2】:

      您可以根据需要使用“layout:coloumnSpan”或“layout:rowSpan”使对象“合并”在两列或两行上。只需将值设置为 2 即可合并超过 2 行/列。

      【讨论】:

      • 你如何以编程方式做到这一点?
      猜你喜欢
      • 2013-04-15
      • 1970-01-01
      • 1970-01-01
      • 2014-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多