gpt4 book ai didi

c# - 具有合并单元格的 GridView

转载 作者:可可西里 更新时间:2023-11-01 03:08:39 25 4
gpt4 key购买 nike

我需要在 GridView 中显示某些列的合并行的数据。请帮助我准备以下定义格式的 GridView : enter image description here

来自数据库的原始数据格式如下: enter image description here

请帮助我找到动态高效地完成此任务的最佳方法。

最佳答案

您将不得不使用 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

关于c# - 具有合并单元格的 GridView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16147963/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com