出自ProgWiki
原理
- 複寫 GridView1 的 RowCreated 事件處理函式。
- 重點在於除了最後一行以外, 每一行檔頭的最後要用
</th></tr><tr>
隔開做為檔頭換行。
程式碼範例
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
switch(e.Row.RowType)
{
case DataControlRowType.Header:
TableCellCollection tcHeader = e.Row.Cells;
tcHeader.Clear();
string strCssClass = "ColumnNameCenter";
//L1
tcHeader.Add(new TableHeaderCell());
tcHeader[0].Attributes.Add("colspan", "9");
tcHeader[0].Attributes.Add("class", strCssClass);
tcHeader[0].Attributes.Add("style", "text-align:left");
tcHeader[0].Text = string.Format(
"資料年月:{0}年{1}月</th></tr><tr>",
this.Request.QueryString["Year"],
this.Request.QueryString["Month"]);
//L2
tcHeader.Add(new TableHeaderCell());
tcHeader[1].Attributes.Add("colspan", "9");
tcHeader[1].Attributes.Add("class", strCssClass);
tcHeader[1].Text = "生產用庫存控管表</th></tr><tr>";
//L3
tcHeader.Add(new TableHeaderCell());
tcHeader[2].Attributes.Add("rowspan", "3");
tcHeader[2].Attributes.Add("class", strCssClass);
tcHeader[2].Text = " ";
tcHeader.Add(new TableHeaderCell());
tcHeader[3].Attributes.Add("rowspan", "3");
tcHeader[3].Attributes.Add("class", strCssClass);
tcHeader[3].Text = "日期";
tcHeader.Add(new TableHeaderCell());
tcHeader[4].Attributes.Add("rowspan", "3");
tcHeader[4].Attributes.Add("class", strCssClass);
tcHeader[4].Text = "產量";
tcHeader.Add(new TableHeaderCell());
tcHeader[5].Attributes.Add("rowspan", "3");
tcHeader[5].Attributes.Add("class", strCssClass);
tcHeader[5].Text = "用量";
tcHeader.Add(new TableHeaderCell());
tcHeader[6].Attributes.Add("colspan","4");
tcHeader[6].Attributes.Add("class", strCssClass);
tcHeader[6].Text = "入庫數量";
tcHeader.Add(new TableHeaderCell());
tcHeader[7].Attributes.Add("rowspan", "3");
tcHeader[7].Attributes.Add("class", strCssClass);
tcHeader[7].Text = "實際庫存</th></tr><tr>";
//L4
tcHeader.Add(new TableHeaderCell());
tcHeader[8].Attributes.Add("colspan", "2");
tcHeader[8].Attributes.Add("class", strCssClass);
tcHeader[8].Text = "進貨";
tcHeader.Add(new TableHeaderCell());
tcHeader[9].Attributes.Add("colspan", "2");
tcHeader[9].Attributes.Add("class", strCssClass);
tcHeader[9].Text = "借貨</th></tr><tr>";
//L5
tcHeader.Add(new TableHeaderCell());
tcHeader[10].Attributes.Add("class", strCssClass);
tcHeader[10].Text = "數量";
tcHeader.Add(new TableHeaderCell());
tcHeader[11].Attributes.Add("class", strCssClass);
tcHeader[11].Text = "明細";
tcHeader.Add(new TableHeaderCell());
tcHeader[12].Attributes.Add("class", strCssClass);
tcHeader[12].Text = "數量";
tcHeader.Add(new TableHeaderCell());
tcHeader[13].Attributes.Add("class", strCssClass);
tcHeader[13].Text = "累積";
break;
case DataControlRowType.Footer:
break;
case DataControlRowType.DataRow:
break;
case DataControlRowType.EmptyDataRow:
break;
}
}
相關