2012-09-20 81 views

回答

0

合併排在同一列中,您choule使用這樣的代碼:

public static void GroupRows(GridView GridView1, int cellNum) 
{ 
    int i = 0, rowSpanNum = 1; 
    while (i < GridView1.Rows.Count - 1) 
    { 
     GridViewRow gvr = GridView1.Rows[i]; 
     for (++i; i < GridView1.Rows.Count; i++) 
     { 
      GridViewRow gvrNext = GridView1.Rows[i]; 
      if (gvr.Cells[cellNum].Text != "" && gvrNext.Cells[cellNum].Text == "") ///here, chould change the term to suit other conditions, such like merging the same content of different rows in a same column. 
      { 
       gvrNext.Cells[cellNum].Visible = false; 
       rowSpanNum++; 
      } 
      else 
      { 
       gvr.Cells[cellNum].RowSpan = rowSpanNum; 
       rowSpanNum = 1; 
       break; 
      } 
      if (i == GridView1.Rows.Count - 1) 
      { 
       gvr.Cells[cellNum].RowSpan = rowSpanNum; 
      } 
     } 
    } 
} 
0

您可以使用「佈局:coloumnSpan」或「佈局:行跨度」使對象「合併」了根據需要設置兩列或兩行。只需將該值設置爲2,即可合併成2行/列。

+1

你如何以編程的方式做到這一點? –