带有合并单元格的 GridView [英] GridView with merged cells
本文介绍了带有合并单元格的 GridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在网格视图中显示某些列的合并行的数据.请帮我准备以下定义格式的网格视图:
I need to display data in grid view with merged rows for some columns. Please help me to prepare a grid view in below defined format:
来自数据库的原始数据格式如下:
And the original data comes from database is in below format:
请帮助我找到动态有效地完成这项任务的最佳方式.
Please help me to find best way for doing this task dynamically and efficiently.
推荐答案
你将不得不使用 RowSpan
.
参考以下代码:
protected void GridView1_DataBound1(object sender, EventArgs e)
{
for (int rowIndex = GridView1.Rows.Count - 2;
rowIndex >= 0; rowIndex--)
{
GridViewRow gvRow = GridView1.Rows[rowIndex];
GridViewRow gvPreviousRow = GridView1.Rows[rowIndex + 1];
for (int cellCount = 0; cellCount < gvRow.Cells.Count;
cellCount++)
{
if (gvRow.Cells[cellCount].Text ==
gvPreviousRow.Cells[cellCount].Text)
{
if (gvPreviousRow.Cells[cellCount].RowSpan < 2)
{
gvRow.Cells[cellCount].RowSpan = 2;
}
else
{
gvRow.Cells[cellCount].RowSpan =
gvPreviousRow.Cells[cellCount].RowSpan + 1;
}
gvPreviousRow.Cells[cellCount].Visible = false;
}
}
}
参考:
https://sites.google.com/site/learning6329/asp-net/gridview-merge-cells
问题中的图片示例:
http://marss.co.ua/MergingCellsInGridView.aspx
这篇关于带有合并单元格的 GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文