[英]Merging Last column in the gridview according to first column
我有合並第一列的gridview。 我在數據綁定中使用了以下代碼。
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 - 3; 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;
}
}
}
我想根據第一列合並最后一列。
我嘗試了以下代碼。 但這沒有用。
for (int t = 0; t < GridView1.Rows.Count; t++)
{
GridView1.Rows[t].Cells[3].RowSpan = GridView1.Rows[t].Cells[0].RowSpan;
}
誰能幫我做到這一點?
提前致謝
正如我在評論中所說,如果您希望第四行與第三行合並,則應在第三列上設置merge屬性。
for (int t = 0; t < GridView1.Rows.Count; t++)
{
GridView1.Rows[t].Cells[2].RowSpan = GridView1.Rows[t].Cells[0].RowSpan;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.