如何水平合并GridView的单元格(不是页眉或页脚)? [英] How to merge GridView's Cells(not Headers or Footers) horizontally?
问题描述
大家好,
我有一个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.
推荐答案
最好的解决方案已在互联网上提供。请使用Google。
提示:在RowDataBound
GridView事件中,您可以循环遍历行的单元格。如果您发现类似的文本,请合并它们。从rowIndex
开始,因为你不会合并标题[更好地说在事件中忽略标题],对吧?如果你需要更多的澄清,请告诉我。
问候..
Finest and best solution is already available on internet. Please use Google.
Hint: InRowDataBound
Event of GridView, you are suppose to loop through Cells of row . If you find text similar,merge them. Start this fromrowIndex
of 1 because you will not be merging the Header[Better to say ignore header in the Event],right? Let me know if you need more clarification on this.
Regards..
你好,你可以试试这段代码:
Hello freind, you may try this code:
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的单元格(不是页眉或页脚)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!