GridView控件与合并单元格 [英] GridView with merged cells
本文介绍了GridView控件与合并单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要显示在某些列合并行网格视图的数据。请帮我prepare在下面定义的格式网格视图:
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
。
请参考以下code它:
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;
}
}
}
全球化志愿服务青年:
<一个href=\"https://sites.google.com/site/learning6329/asp-net/gridview-merge-cells\">https://sites.google.com/site/learning6329/asp-net/gridview-merge-cells
画报例如在问:
<一个href=\"http://marss.co.ua/MergingCellsInGridView.aspx\">http://marss.co.ua/MergingCellsInGridView.aspx
这篇关于GridView控件与合并单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文