- /// <summary>
 
 - /// ===================  两行标题行  ========================
 
 - /// </summary>
 
 - /// <param name="sender"></param>
 
 - /// <param name="e"></param>
 
 - protected void GV1_RowCreated(object sender, GridViewRowEventArgs e)
 
 - {
 
 -     if (e.Row.RowType == DataControlRowType.Header)
 
 -     {
 
 -         e.Row.Cells.Clear();
 
 -         string[] capText = { "ID", "材料名称", "规格型号", "计量单位", "入库数量", "点验", "发料", "库存", "合同" };
 
 -         int[] capWidth = { 50, 0, 0, 0, 70, 150, 150, 150, 150 };
 
 -         int[] capRowSpan = { 2, 2, 2, 2, 2, 1, 1, 1, 1 };
 
 -         int[] capColSpan = { 1, 1, 1, 1, 1, 2, 2, 2, 2 };
 
 -         GV1.Controls[0].Controls.Add(CreateHeaderRow(capText, capWidth, capRowSpan, capColSpan));
 
  
-         capText = new string[] { "数量", "金额", "数量", "金额", "数量", "金额", "单价", "金额" };
 
 -         capWidth = new int[] { 70, 80, 70, 80, 70, 80, 70, 80 };
 
 -         GV1.Controls[0].Controls.Add(CreateHeaderRow(capText, capWidth, capRowSpan, capColSpan, true));
 
 -     }
 
 - }
 
 - /// <summary>
 
 - /// =====================  自定义标题行的方法  =========================
 
 - /// </summary>
 
 - /// <param name="tcText">单元格Text</param>
 
 - /// <param name="tcWidth">单元格宽度,为0则不设置宽度</param>
 
 - /// <param name="tcRowSpan">RowSpan</param>
 
 - /// <param name="tcColSpan">ColumnSpan</param>
 
 - /// <param name="noSpanRow">若为True,则忽略行、列的合并Span</param>
 
 - /// <returns>一行标题行</returns>
 
 - private GridViewRow CreateHeaderRow(string[] tcText, int[] tcWidth, int[] tcRowSpan, int[] tcColSpan, bool noSpanRow = false)
 
 - {
 
 -     GridViewRow rowHeader = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
 
 -     TableHeaderCell thc;
 
 -     for (int i = 0; i < tcText.Length; i++)
 
 -     {
 
 -         thc = new TableHeaderCell();
 
 -         thc.Text = tcText[i];
 
 -         if (tcWidth[i] > 0) { thc.Width = tcWidth[i]; }//若为0,则不设置width
 
 -         if (!noSpanRow)
 
 -         {
 
 -             if (tcRowSpan[i] != 1) { thc.RowSpan = tcRowSpan[i]; }
 
 -             if (tcColSpan[i] != 1) { thc.ColumnSpan = tcColSpan[i]; }
 
 -         }
 
 -         rowHeader.Cells.Add(thc);
 
 -     }
 
 -     return rowHeader;
 
 - }
 
  复制代码 
 
摘自:https://www.cnblogs.com/xuse/p/3570688.html |