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