How to merge two cells in gridview

痴心易碎 提交于 2020-01-04 03:03:47

问题


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

A     B
1     
2     adeel
3
4     sml

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


回答1:


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



回答2:


You can use "layout:coloumnSpan" or "layout:rowSpan" to make an object "merge" over two columns or rows as required. Simply set the value to 2 for it to merge over 2 rows/columns.



来源:https://stackoverflow.com/questions/12512771/how-to-merge-two-cells-in-gridview

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!