This is a migrated thread and some comments may be shown as answers.

Put two columns under a header.

3 Answers 144 Views
Grid
This is a migrated thread and some comments may be shown as answers.
aks
Top achievements
Rank 1
aks asked on 24 Oct 2011, 10:51 PM
I have a radgrid where I want to put two columns under a header.  I am attaching a screenshot to this thread to show you what I want.  You will see the column "Open Items by Age" is further divided as "Prior" and "Current" columns.  Is this possible to do in a radgrid and still maintain the sort for the "Prior" and "Current" columns.  I am attaching code to help you see my grid.

Thanks in advance!


<telerik:RadGrid ID="grdCurrentandPrior" runat="server" AllowSorting="True" AutoGenerateColumns="False"
                        GridLines="Horizontal" Skin="Web20" Style="margin-right: 0px" Width="897px" Height="252px"
                        OnNeedDataSource="grdCurrentandPrior_NeedDataSource" OnExcelMLExportRowCreated="grdCurrentandPrior_ExcelMLExportRowCreated" OnSortCommand="grdCurrentandPrior_SortCommand">
                        <ExportSettings FileName="OpenItemsCurrentInventory" IgnorePaging="True" OpenInNewWindow="True"
                            ExportOnlyData="true" Excel-Format="ExcelML">
                        </ExportSettings>
                        <MasterTableView CommandItemDisplay="Bottom" AllowNaturalSort="false" UseAllDataFields="true">
                            <CommandItemSettings ShowExportToExcelButton="true" ShowAddNewRecordButton="false"
                                ShowRefreshButton="false" />
                            <Columns>
                                <telerik:GridTemplateColumn DataField="Assignee" HeaderText="Assignee" UniqueName="Assignee"
                                    SortExpression="Assignee">
                                    <HeaderStyle Font-Bold="True" Width="150px" HorizontalAlign="Center" Font-Names="Arial" />
                                    <ItemTemplate>
                                        <asp:Label ID="lbAssignee" runat="server" Text='<%# Eval("Assignee") %>'></asp:Label>
                                    </ItemTemplate>
                                    <FooterStyle HorizontalAlign="Right" Font-Bold="true" />
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn DataField="State" HeaderText="State" UniqueName="State"
                                    SortExpression="State" Visible="false">
                                    <HeaderStyle Font-Bold="True" Width="150px" HorizontalAlign="Center" Font-Names="Arial" />
                                    <ItemTemplate>
                                        <asp:Label ID="lbState" runat="server" Text='<%# Eval("State") %>'></asp:Label>
                                    </ItemTemplate>
                                    <FooterStyle HorizontalAlign="Right" Font-Bold="true" />
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn DataField="JurisdictionCount" HeaderText="Jurisdictions"
                                    UniqueName="JurisdictionCount" SortExpression="JurisdictionCount">
                                    <HeaderStyle Font-Bold="True" Width="80px" HorizontalAlign="Center" Font-Names="Arial" />
                                    <ItemTemplate>
                                        <asp:Label ID="lbJurisdiction" runat="server" Text='<%# Eval("JurisdictionCount", "{0:N0}")%>'></asp:Label>
                                    </ItemTemplate>
                                    <ItemStyle HorizontalAlign="Right" ForeColor="Black" />
                                    <FooterStyle HorizontalAlign="Right" Font-Bold="true" />
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn DataField="OpenItemsCountPrior" HeaderText="Prior Open Items"
                                    UniqueName="OpenItemsCountPrior" SortExpression="OpenItemsCountPrior">
                                    <HeaderStyle Font-Bold="True" Width="80px" HorizontalAlign="Center" Font-Names="Arial" />
                                    <ItemTemplate>
                                        <asp:Label ID="lbPrior" runat="server" Text='<%# Eval("OpenItemsCountPrior", "{0:N0}") %>'></asp:Label>
                                    </ItemTemplate>
                                    <ItemStyle HorizontalAlign="Right" ForeColor="Black" />
                                    <FooterStyle HorizontalAlign="Right" Font-Bold="true" />
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn DataField="OpenItemsCountLastMonth" HeaderText="Last Month Items"
                                    UniqueName="OpenItemsCountLastMonth" SortExpression="OpenItemsCountLastMonth">
                                    <HeaderStyle Font-Bold="True" Width="80px" HorizontalAlign="Center" Font-Names="Arial" />
                                    <ItemTemplate>
                                        <asp:Label ID="lbLastMonth" runat="server" Text='<%# Eval("OpenItemsCountLastMonth", "{0:N0}") %>'></asp:Label>
                                    </ItemTemplate>
                                    <ItemStyle HorizontalAlign="Right" ForeColor="Black" />
                                    <FooterStyle HorizontalAlign="Right" Font-Bold="true" />
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn DataField="OpenItemsCountCurrent" HeaderText="Current Open Items"
                                    UniqueName="OpenItemsCountCurrent" SortExpression="OpenItemsCountCurrent">
                                    <HeaderStyle Font-Bold="True" Width="100px" HorizontalAlign="Center" Font-Names="Arial" />
                                    <ItemTemplate>
                                        <asp:Label ID="lbCurrent" runat="server" Text='<%# Eval("OpenItemsCountCurrent", "{0:N0}") %>'></asp:Label>
                                    </ItemTemplate>
                                    <ItemStyle HorizontalAlign="Right" ForeColor="Black" />
                                    <FooterStyle HorizontalAlign="Right" Font-Bold="true" />
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn DataField="TotalRemainingItems" HeaderText="Items Left to Pay"
                                    UniqueName="TotalRemainingItems" SortExpression="TotalRemainingItems">
                                    <HeaderStyle Font-Bold="True" Width="95px" HorizontalAlign="Center" Font-Names="Arial" />
                                    <ItemTemplate>
                                        <asp:Label ID="lblTotalRemain" runat="server" Text='<%# Eval("TotalRemainingItems", "{0:N0}") %>'></asp:Label>
                                    </ItemTemplate>
                                    <ItemStyle HorizontalAlign="Right" ForeColor="Black" />
                                    <FooterStyle HorizontalAlign="Right" Font-Bold="true" />
                                </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn DataField="CompleteCount" HeaderText="Complete"
                                    UniqueName="CompleteCount" SortExpression="CompleteCount">
                                    <HeaderStyle Font-Bold="True" Width="80px" HorizontalAlign="Center" Font-Names="Arial" />
                                    <ItemTemplate>
                                        <asp:Label ID="lblCompleteCount" runat="server" Text='<%# Eval("CompleteCount", "{0:N0}") %>'></asp:Label>
                                    </ItemTemplate>
                                    <ItemStyle HorizontalAlign="Right" ForeColor="Black" />
                                    <FooterStyle HorizontalAlign="Right" Font-Bold="true" />
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn DataField="PercentComplete" HeaderText="% Complete" UniqueName="clmPctComplete"
                                    SortExpression="PercentComplete">
                                    <HeaderStyle Font-Bold="True" Width="85px" HorizontalAlign="Center" Font-Names="Arial" />
                                    <ItemTemplate>
                                        <asp:Label ID="lblPctComplete" runat="server" Text='<%# Eval("PercentComplete", "{0:N2}%")%>'></asp:Label>
                                    </ItemTemplate>
                                    <ItemStyle HorizontalAlign="Right" ForeColor="Black" />
                                    <FooterStyle HorizontalAlign="Right" Font-Bold="true" />
                                </telerik:GridTemplateColumn>
                                <telerik:GridBoundColumn DataField="AssigneeEmployeeKey" ReadOnly="True" UniqueName="AssigneeEmployeeKey"
                                    Visible="False">
                                </telerik:GridBoundColumn>
                            </Columns>
                        </MasterTableView>
                        <HeaderStyle BorderStyle="Solid" />
                        <ClientSettings>
                            <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                        </ClientSettings>
                    </telerik:RadGrid>

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 25 Oct 2011, 05:05 AM
Hello,

You can try the same approach in the following help documentation to achieve your scenario.
Customizing with GridTemplateColumn.

Thanks,
Shinu.
0
aks
Top achievements
Rank 1
answered on 25 Oct 2011, 09:09 PM
Thanks!  I have another question, how can I export this to Excel?  My grid exports to Excel but does not include the columns using this solution.
0
Shinu
Top achievements
Rank 2
answered on 27 Oct 2011, 06:07 AM
Hello,

You can try the following approach to export GridTemplateColumns.
C#:
protected void export_Click(object sender, EventArgs e)
{
  RadGrid1.ExportSettings.ExportOnlyData = true;
  RadGrid1.MasterTableView.GetColumn("Assignee").Visible = true;
  RadGrid1.MasterTableView.ExportToExcel();
  RadGrid1.Rebind();
}

Thanks,
Shinu.
Tags
Grid
Asked by
aks
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
aks
Top achievements
Rank 1
Share this question
or