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     }
     
  • 相关阅读:
    「两千年中公历转换」数据库介绍
    [转]Web中使用Word控件。(DSOFramer )
    解决DRIVE_IRQL_NOT_LESS_OR_EQUAL的方法
    Html Img的几个属性_存在个问题
    不错的开源C#博客_BlogEngine.net
    [转]引用指定的namespace 解决命名空间冲突的错误
    [原]不太完善的图像合并程序VS2005CSharp_有目录监控_TIF_JPG输出
    [转]JS小游戏_9格的棋
    JS小游戏_能坚持几秒
    [转]前台JS限制上传图片质量大小和尺寸!
  • 原文地址:https://www.cnblogs.com/xuse/p/3570688.html
Copyright © 2011-2022 走看看