UltraWebGrid多表头的实现

  1. 首先在中设置好列,这里默认设置的列是col1,col2_1,col2_2,col3.其中col2_1和col2_2是要生成多表头的列。
  2. 的InitializeLayout事件中写如下代码:
    // All the Headers for bound columns initialize to OriginX = 0.
    1. // Since we want them
    2. // to appear below the added column headers
    3. //we are going to need to move them down a level
    4. //先把所有列头都设为第二行
    5. foreach (Infragistics.WebUI..UltraGridColumn
    6.  c in UltraWebGrid1.DisplayLayout.Bands[0].Columns)
    7. {
    8.  c.Header.RowLayoutColumnInfo.OriginY = 1;
    9. //纵向起始点,0为第一行,1为第二行
    10. }
    11. //创建一个列头对象
    12. var ch = new
    13. Infragistics.WebUI..ColumnHeader(true);
    14. ch.Caption = "表头";   //列头文本标题
    15. ch.RowLayoutColumnInfo.OriginX = 1;   //横向起始点,0为第一列,1为第二列
    16. ch.RowLayoutColumnInfo.OriginY = 0;   //纵向起始点,0为第一行,1为第二行
    17. ch.RowLayoutColumnInfo.SpanX = 2;   //设置横向跨度
    18. e.DisplayLayout.HeaderStyleDefault.Height = Unit.Pixel(15);
    19. e.Layout.Bands[0].HeaderLayout.Add(ch); //增加到列头集合中
    20. //把非多表头的列,进行跨行
    21. foreach (Infragistics.WebUI..UltraGridColumn
    22. c in e.Layout.Bands[0].Columns)
    23. {
    24.   if (c.Key != "col2_1" && c.Key != "col2_2")
    25.  //c.Key 非多表头列的key值
    26.   {
    27.    c.Header.RowLayoutColumnInfo.OriginY = 0; //从第一行开始
    28.    c.Header.RowLayoutColumnInfo.SpanY = 2; //跨2行
    29.    }
    30. }
  3. 绑定数据源。只有在绑定数据源后,多表头格式才显示。
标签:, ,

相关日志