2013-07-04 40 views
0

我有一個合併了第一列的gridview。我在數據綁定中使用了下面的代碼。根據第一列合併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;    
} 

任何人都可以幫助我做到這一點?正如我在評論說

+0

你有多少列?你可能想要在最後一個合併。 – AlexDev

+0

我有四個欄目。第一個是合併。然後我想合併最後一個。但是我想根據第一列合併最後一列。 – Shanna

回答

1

由於提前,如果你想第4行與您應該設置在第三列合併財產第三合併。

for (int t = 0; t < GridView1.Rows.Count; t++) 
{ 
    GridView1.Rows[t].Cells[2].RowSpan = GridView1.Rows[t].Cells[0].RowSpan;    
} 
+0

它沒有工作。感謝回覆 – Shanna

相關問題