protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
   // 檢查是不是標題列
   if (e.Row.RowType == DataControlRowType.Header)
   {
      // 建立自訂的標題
      GridView gv = (GridView)sender;
      GridViewRow gvRow = new
         GridViewRow(0, 0, DataControlRowType.Header,
         DataControlRowState.Insert);

      // 增加 Department 欄位
      TableCell tc1 = new TableCell();
      tc1.Text = "Department";
      tc1.ColumnSpan = 2;   // 跨兩欄
      gvRow.Cells.Add(tc1);

      // 增加 Employee 欄位
      TableCell tc2 = new TableCell();
      tc2.Text = "Employee";
      tc2.ColumnSpan = 3;   // 跨三欄
      gvRow.Cells.Add(tc2);

      // 把這一列加到最上面
      gv.Controls[0].Controls.AddAt(0, gvRow);
   }
}
posted on 2009-04-01 10:54  情感星  阅读(296)  评论(0)    收藏  举报