zoukankan      html  css  js  c++  java
  • GridView多行标题行、改造标题行、自定义标题行完美版

    网上找了个找,最终还是自己做的比较靠谱,道理很简单,直接看代码

    代码:
     
     1     /// <summary>
     2     /// ===================  两行标题行  ========================
     3     /// </summary>
     4     /// <param name="sender"></param>
     5     /// <param name="e"></param>
     6     protected void GV1_RowCreated(object sender, GridViewRowEventArgs e)
     7     {
     8         if (e.Row.RowType == DataControlRowType.Header)
     9         {
    10             e.Row.Cells.Clear();
    11             string[] capText = { "ID", "材料名称", "规格型号", "计量单位", "入库数量", "点验", "发料", "库存", "合同" };
    12             int[] capWidth = { 50, 0, 0, 0, 70, 150, 150, 150, 150 };
    13             int[] capRowSpan = { 2, 2, 2, 2, 2, 1, 1, 1, 1 };
    14             int[] capColSpan = { 1, 1, 1, 1, 1, 2, 2, 2, 2 };
    15             GV1.Controls[0].Controls.Add(CreateHeaderRow(capText, capWidth, capRowSpan, capColSpan));
    16 
    17             capText = new string[] { "数量", "金额", "数量", "金额", "数量", "金额", "单价", "金额" };
    18             capWidth = new int[] { 70, 80, 70, 80, 70, 80, 70, 80 };
    19             GV1.Controls[0].Controls.Add(CreateHeaderRow(capText, capWidth, capRowSpan, capColSpan, true));
    20         }
    21     }
    22     /// <summary>
    23     /// =====================  自定义标题行的方法  =========================
    24     /// </summary>
    25     /// <param name="tcText">单元格Text</param>
    26     /// <param name="tcWidth">单元格宽度,为0则不设置宽度</param>
    27     /// <param name="tcRowSpan">RowSpan</param>
    28     /// <param name="tcColSpan">ColumnSpan</param>
    29     /// <param name="noSpanRow">若为True,则忽略行、列的合并Span</param>
    30     /// <returns>一行标题行</returns>
    31     private GridViewRow CreateHeaderRow(string[] tcText, int[] tcWidth, int[] tcRowSpan, int[] tcColSpan, bool noSpanRow = false)
    32     {
    33         GridViewRow rowHeader = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
    34         TableHeaderCell thc;
    35         for (int i = 0; i < tcText.Length; i++)
    36         {
    37             thc = new TableHeaderCell();
    38             thc.Text = tcText[i];
    39             if (tcWidth[i] > 0) { thc.Width = tcWidth[i]; }//若为0,则不设置width
    40             if (!noSpanRow)
    41             {
    42                 if (tcRowSpan[i] != 1) { thc.RowSpan = tcRowSpan[i]; }
    43                 if (tcColSpan[i] != 1) { thc.ColumnSpan = tcColSpan[i]; }
    44             }
    45             rowHeader.Cells.Add(thc);
    46         }
    47         return rowHeader;
    48     }
     
  • 相关阅读:
    算法导论(第三版)Exercises2.1(插入排序、线性查找、N位大数相加)
    含铝馒头可能损伤儿童的智力
    每秒3600乘以100等于36万次售票解决方案
    namespace Measure
    public interface ICloneable
    VB.net 与线程
    C#调用VP 包含素材
    C# 定时器 一个简单 并且可以直接运行的Demo
    松下 激光位移传感器 API
    在Win7系统下, 使用VS2015 打开带有日文注释程序出现乱码的解决方案
  • 原文地址:https://www.cnblogs.com/xuse/p/3570688.html
Copyright © 2011-2022 走看看