博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

複雜表頭

Posted on 2007-04-12 09:19  徐正柱-  阅读(283)  评论(0编辑  收藏  举报

1. 在ItemCreated時重新生成(寫Html)
private void Datagrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
  {
   if(e.Item.ItemType == ListItemType.Header)
   {
    e.Item.SetRenderMethodDelegate(new RenderMethod(NewRenderMethod));
   }
  }


private void NewRenderMethod(HtmlTextWriter writer, Control ctl)
  {
   NPTR.ICL.Command cm=new Command();
   string date=System.DateTime.Now.Date.ToShortDateString();
   string week=cm.GetWeekName(date).Substring(1);
   int wk=Convert.ToInt32(week);

   writer.Write(" <tr align=\"Center\" style=\"color:White;background-color:SeaGreen;font-weight:bold;height:20px;\"> ");
   writer.Write("<td rowspan=\"2\" style=\"width:100px;\">Model Name</td><td rowspan=\"2\" style=\"width:100px;\">Project Name</td>");
   writer.Write("<td rowspan=\"2\" style=\"width:75px;\">PM</td><td rowspan=\"2\" style=\"width:90px;\">試作編號</td>");
   writer.Write("<td rowspan=\"2\" style=\"width:125px;\">產品開發階段</td>");
    for(int i=1;i<=4;i++)
   {
    writer.Write("<td colspan=\"3\">W"+wk + " </td> ");
    wk++;
   }
 
   writer.Write("</tr> ");
   writer.Write("<tr align=\"Center\" valign=\"Middle\" style=\"color:White;background-color:SeaGreen;font-weight:bold;\"> ");
   writer.Write("<td style=\"width:120px;\">預計投入日期</td><td style=\"width:120px;\">預計投入數量</td>");
   writer.Write("<td style=\"width:110px;\">BOM Version</td>");
   writer.Write("<td style=\"width:120px;\">預計投入日期</td>");
   writer.Write("<td style=\"width:120px;\">預計投入數量</td>");
   writer.Write("<td style=\"width:110px;\">BOM Version</td>");
   writer.Write("<td style=\"width:120px;\">預計投入日期</td>");
   writer.Write("<td style=\"width:120px;\">預計投入數量</td>");
   writer.Write("<td style=\"width:110px;\">BOM Version</td>");
   writer.Write("<td style=\"width:120px;\">預計投入日期</td>");
   writer.Write("<td style=\"width:120px;\">預計投入數量</td>");
   writer.Write("<td style=\"width:110px;\">BOM Version</td>");
   writer.Write("</tr>");

  }

-------------------------------------------------------------------------------------------------------------------------------
2.在ItemCreated時重新生成(Control 添加TalbeCell,也可添加Table)

private void Datagrid_105_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
  {
   #region Build DataGrid Header 105
   ListItemType ItemType = e.Item.ItemType;
   if (ItemType == ListItemType.Pager)
   {
    if (upPager105)
    {
     TableCell CellGR105 =  (TableCell) e.Item.Controls[0];
     CellGR105.Controls.Clear();
     CellGR105.BackColor = Color.FromName("#009F62") ;
     CellGR105.ForeColor =System.Drawing.Color.LightYellow; 
     CellGR105.ColumnSpan = 2; 
     CellGR105.HorizontalAlign = HorizontalAlign.Center; 
     CellGR105.Controls.Add(new LiteralControl("GR 105(原物料倉)"));
     e.Item.Controls.Add(CellGR105);
     upPager105 = false; 
    }
   }
   #endregion
  }