本文介绍了如何水平合并GridView的单元格(不是页眉或页脚)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个Gridview,我需要合并我最后一行的单元格(不是页脚)。

我已经搜索了所有内容并且没有找到关于此问题的解决方案,因为有许多解决方案可以垂直合并单元格或合并页眉或页脚。



我的GridView:



|任务号|用户名|主题|请求类型|参考文件|

| 123456 | Mr.XYZABC |演示|测试需求|找不到档案|

|备注|这是我需要在所有列上合并的单元格。 |

|任务号|用户名|主题|请求类型|参考文件|

| 123457 | Mr.AAAAAA | DEMO2 |测试需求|找不到档案|

|备注|这是我需要在所有列上合并的单元格。 |

|任务号|用户名|主题|请求类型|参考文件|

| 123458 | Mr.XXXXXX | DEMO3 |测试需求|找不到档案|

|备注|这是我需要在所有列上合并的单元格。 |



在一个按钮上单击我在同一网格视图中每次绑定3行。

第1行:05列

第二行:05列

第三行:02列(备注,这是我需要的单元格..... [Colspan = 4])



在这个例子中,您可以看到在一个按钮上单击我生成3行,最后一行单元格应该合并。





对于最好和最好的解决方案感到高兴。请帮忙。 :)



谢谢&此致,

AR。

Hi All,

I have a Gridview in which I need to merge cells of my last row (Not the Footer).
I have Googled everything and found no solution regarding this issue as there are many solutions to merge cells vertically or merging headers or footers.

My GridView:

| Task No | User Name | Subject | Request Type | Reference File |
| 123456 | Mr.XYZABC | DEMO | Testing Req | No Files Found |
| Remark | This is the cell I need to merge on all columns. |
| Task No | User Name | Subject | Request Type | Reference File |
| 123457 | Mr.AAAAAA | DEMO2 | Testing Req | No Files Found |
| Remark | This is the cell I need to merge on all columns. |
| Task No | User Name | Subject | Request Type | Reference File |
| 123458 | Mr.XXXXXX | DEMO3 | Testing Req | No Files Found |
| Remark | This is the cell I need to merge on all columns. |

On one button Click I am Binding 3 rows each time in a same gridview.
1st Row: 05 Columns
2nd Row: 05 Columns
3rd Row: 02 Columns (Remarks , This is the cell I need .....[Colspan=4])

In this example you can see that on one button click I am generating 3 rows and the last row cells should be merged.


Will be glad for the finest and best solution. Help Please. :)

Thanks & Regards,
AR.

推荐答案


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        if (e.Row.RowIndex > 0)
        {
            int colSpanValue = 2;
            //Loop through all the cells in the row
            for (int i = 0; i < e.Row.Cells.Count - 1; i++)
            {
                //Checking If current cell is same as next cell value
                if (e.Row.Cells[i].Text == e.Row.Cells[i + 1].Text)
                {
                    e.Row.Cells[i].ColumnSpan = colSpanValue;
                    e.Row.Cells[i + 1].Visible = false;
                    colSpanValue++;
                }
            }
        }
    }
}


这篇关于如何水平合并GridView的单元格(不是页眉或页脚)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 14:45