Generally, when designing a Grid multi-row header, we may first consider using Repeater or DataList, but now we can use Infragistics's WebGrid to easily implement this function, the implementation is as follows:
The code for implementing such a header is as follows:
Add the following code to the Grid InitializeLayout event:
//
// Design multiple headers
//
Private void ut_grid105_InitializeLayout (object sender, Infragistics. WebUI. UltraWebGrid. LayoutEventArgs e)
{
Foreach (Infragistics. WebUI. UltraWebGrid. ultratedcolumn c in e. Layout. Bands [0]. Columns)
{
C. Header. RowLayoutColumnInfo. OriginY = 1;
}
// Create a new header and set its display name
Infragistics. WebUI. UltraWebGrid. ColumnHeader ch = new ColumnHeader (true );
Ch. Caption = "purchase volume ";
// Set the start position of the Y axis
Ch. RowLayoutColumnInfo. OriginY = 0;
// Set the start position of the X axis
Ch. RowLayoutColumnInfo. OriginX = 4;
// Set the number of columns in the X axis of the header.
Ch. RowLayoutColumnInfo. SpanX = 2;
// Add the header to our Grid.
E. Layout. Bands [0]. HeaderLayout. Add (ch );
Infragistics. WebUI. UltraWebGrid. ColumnHeader attributes = new ColumnHeader (true );
Ch1.Caption = "consumption ";
Ch1.RowLayoutColumnInfo. OriginY = 0;
Ch1.RowLayoutColumnInfo. origtables = 6;
Ch1.RowLayoutColumnInfo. SpanX = 5;
E. Layout. Bands [0]. HeaderLayout. Add (scheme );
Foreach (Infragistics. WebUI. UltraWebGrid. ultratedcolumn c in e. Layout. Bands [0]. Columns)
{
If (c. Key! = "A02" & c. Key! = "A03" & c. Key! = "A04" & c. Key! = "A05" & c. Key! = "A06" & c. Key! = "A07" & c. Key! = "A08 ")
{
C. Header. RowLayoutColumnInfo. OriginY = 0;
C. Header. RowLayoutColumnInfo. SpanY = 2;
}
}
}
Of course, we can also fix a certain column or several columns. The Code is as follows:
// Fixed column
E. Layout. Bands [0]. Columns. FromKey ("zbmc"). Header. Fixed = true;
E. Layout. Bands [0]. Columns. FromKey ("jldw"). Header. Fixed = true;
E. Layout. Bands [0]. Columns. FromKey ("zbdm"). Header. Fixed = true;
The result is that when we drag the scroll bar horizontally, the fixed columns do not move accordingly. This is suitable for some online forms (the table is too long.