0
两行下面是我使用的代码:此代码的合并在GridView控件
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
for (int rowIndex = gridView.Rows.Count - 2;
rowIndex >= 0; rowIndex--)
{
GridViewRow gvRow = gridView.Rows[rowIndex];
GridViewRow gvPreviousRow = gridView.Rows[rowIndex + 1];
for (int cellCount = 0; cellCount < 2; cellCount++)
{
if (gvRow.Cells[cellCount].Text.ToUpper().Trim() ==
gvPreviousRow.Cells[cellCount].Text.ToUpper().Trim())
{
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;
}
}
}
}
输出看起来像this image。 在这里,红圈表示输出中的问题。当单元格到左列不同时,我不希望行合并。例如,如果银行不同,控制办公室不应该合并。
此代码将只合并第一列行。我需要合并前2列行 –
我上面的代码工作正常只有问题是当第二列的行相同,但第一列的行不同 –
检查此代码的列名更改为(INT我= 0;我row.Cells.Count; i ++) if(row.Cells [i] .Text == previousRow.Cells [i] .Text) row.Cells [i] .RowSpan = previousRow.Cells [i ] .RowSpan <2? 2: previousRow.Cells [i] .RowSpan + 1; previousRow.Cells [i] .Visible = false; } } –