ASP.NET Telerik RadControls 2012 创建多列多行表头
在旧版的RadGrid中,想要创建多行多列表头,需要重写GridBenDept_ItemCreated方法,在这个方法里重绘表头,比较麻烦。
在新版的RadGrid中,加入了<ColumnGroups></ColumnGroups>标记,用于设置多行多列的表头。结构规则如下:
引自RadControls_For_ASPNET_AJAX帮助文档
-
A MultiColumn Header can be a child of only one other multicolumn header.
-
A MultiColumn Header must span at least one column.
-
A MultiColumn Header should be defined only for a single row header per level. Hence a multicolumn header always has RowSpan=1.
-
A column can have as a parent only one MultiColumn Header.
-
Each column header can span only a single column. Hence a column header always has ColSpan=1.
-
A column surrounded (in order of definition) by other columns with common multi header cannot have a different multicolumn header on the same or higher row level than the columns that surround it. This rule ensures proper rendering and avoids overlapping of multicolumn headers.
下面分享一个简单的例子,aspx源文件如下:
1 <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" Culture="zh-CN"
2 CellSpacing="0">
3 <MasterTableView>
4 <ColumnGroups>
5 <telerik:GridColumnGroup HeaderText="编制数" Name="BZCount">
6 </telerik:GridColumnGroup>
7 <telerik:GridColumnGroup HeaderText="全年" Name="All" ParentGroupName="BZCount">
8 </telerik:GridColumnGroup>
9 <telerik:GridColumnGroup HeaderText="Q1" Name="Q1" ParentGroupName="BZCount">
10 </telerik:GridColumnGroup>
11 </ColumnGroups>
12 <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
13 <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
14 </RowIndicatorColumn>
15 <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
16 </ExpandCollapseColumn>
17 <Columns>
18 <telerik:GridBoundColumn HeaderText="编号" DataField="No">
19 </telerik:GridBoundColumn>
20 <telerik:GridBoundColumn HeaderText="部门名称" DataField="Name">
21 </telerik:GridBoundColumn>
22 <telerik:GridBoundColumn HeaderText="正编" DataField="AllZB" ColumnGroupName="All"
23 UniqueName="AllZB">
24 </telerik:GridBoundColumn>
25 <telerik:GridBoundColumn HeaderText="派遣" DataField="AllPQ" ColumnGroupName="All"
26 UniqueName="AllZB">
27 </telerik:GridBoundColumn>
28 <telerik:GridBoundColumn HeaderText="正编" DataField="Q1ZB" ColumnGroupName="Q1" UniqueName="Q1ZB">
29 </telerik:GridBoundColumn>
30 <telerik:GridBoundColumn HeaderText="派遣" DataField="Q1PQ" ColumnGroupName="Q1" UniqueName="Q1ZB">
31 </telerik:GridBoundColumn>
32 </Columns>
33 <ItemStyle HorizontalAlign="Center" />
34 <GroupHeaderItemStyle HorizontalAlign="Center" />
35 <HeaderStyle HorizontalAlign="Center" />
36 </MasterTableView>
37 </telerik:RadGrid>
生成的表头如下图:
新生文章,如有不对之处,请指正!