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

Problem with grid appearance when exporting to excel and CommandItemTemplate

2 Answers 49 Views
Grid
This is a migrated thread and some comments may be shown as answers.
andieje
Top achievements
Rank 1
andieje asked on 22 Jul 2009, 03:36 PM
Hi

I have a grid that contains a command item template and this is disrupting the appearance of the grid when i export to excel.
There is no feature here to include a screenshot but basically the command item template is positioned in columns A and B of the grid and then the rest of teh grid is positioned below it but in columns C onwards.

The output looks like this

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x  Command item template
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                                            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                                            GRID
                                            XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Here is the aspx for the grid

<telerik:RadGrid ID="gridJourneys" runat="server"  Width="960px" AutoGenerateColumns="False" GridLines="None" enableEmbeddedSkins="False" skin="SureTrack">  
<MasterTableView DataKeyNames="JourneyID" CommandItemDisplay="Top" AutoGenerateColumns="False" Name="Journeys" ShowFooter="true"  > 
 <CommandItemTemplate> 
  <span class="title"><asp:Label ID="lblTitle" runat="server" Text="Title"></asp:Label></span>  
 <table cellpadding="5" cellspacing="0" style="width:200px">  
 
 <tr> 
    <td style="width:100px">No Journeys:</td> 
    <td style="width:100px"><asp:Label ID="lblNoJourneys" runat="server"></asp:Label></td>  
 </tr> 
 <tr> 
    <td>Total Distance:</td> 
    <td><asp:Label ID="lblTotalDistance" runat="server"></asp:Label></td>  
 </tr> 
 <tr> 
    <td>Total Time:</td> 
    <td><asp:Label ID="lblTotalDuration" runat="server"></asp:Label></td>  
 </tr> 
 
 <tr> 
    <td>Total Idling</td> 
    <td><asp:Label ID="lblTotalIdling" runat="server"></asp:Label></td>  
 </tr> 
 </table> 
 <br /> 
  </CommandItemTemplate> 
 
<NoRecordsTemplate> 
There are no journeys on this date.  
                
</NoRecordsTemplate> 
     <Columns> 
     <telerik:GridBoundColumn DataField="JourneyID" Aggregate="Count" Visible="false" FooterAggregateFormatString="{0}"></telerik:GridBoundColumn> 
    <telerik:GridBoundColumn DataField="StartDateTime" DataFormatString="{0:dd/MM/yy HH:mm}" HeaderText="Start Time" UniqueName="StartDateTime">  
        <ItemStyle Width="85px" /> 
    </telerik:GridBoundColumn> 
    <telerik:GridTemplateColumn HeaderText="Start Location" UniqueName="StartLocation">  
    <ItemTemplate> 
                <asp:label runat="server" id="lblStartLocation"/>  
    </ItemTemplate> 
        <ItemStyle Width="265px" /> 
</telerik:GridTemplateColumn> 
<telerik:GridBoundColumn DataField="EndDateTime"  DataFormatString="{0:dd/MM/yy HH:mm}" HeaderText="End Time" UniqueName="EndDateTime">  
    <ItemStyle Width="85px" /> 
</telerik:GridBoundColumn> 
<telerik:GridTemplateColumn HeaderText="End Location" UniqueName="EndLocation" > 
<ItemTemplate> 
  <asp:label runat="server" id="lblEndLocation"/>  
      
</ItemTemplate> 
    <ItemStyle Width="265px" /> 
</telerik:GridTemplateColumn> 
 
<telerik:GridBoundColumn DataField="TimeTakenInSeconds" DataFormatString="{0}" UniqueName="TimeTakenInSeconds" Aggregate="Sum" FooterAggregateFormatString="{0}" Visible="false" > 
</telerik:GridBoundColumn> 
<telerik:GridBoundColumn DataField="IdlingTimeInSeconds"  DataFormatString="{0}" UniqueName="IdlingTimeInSeconds" Aggregate="Sum" FooterAggregateFormatString="{0}" visible="false" > 
</telerik:GridBoundColumn> 
<telerik:GridBoundColumn HeaderText="Duration" DataField="TimeTaken" UniqueName="TimeTaken">  
 <ItemStyle Width="65px" /> 
</telerik:GridBoundColumn> 
 
<telerik:GridBoundColumn DataField="DistanceTravelled" DataFormatString="{0:F2}" HeaderText="Distance" UniqueName="DistanceTravelled" Aggregate="Sum" FooterAggregateFormatString="{0:F2}">  
    <ItemStyle Width="65px" /> 
</telerik:GridBoundColumn> 
<telerik:GridTemplateColumn HeaderText="On Site" UniqueName="TemplateColumn2">  
<ItemTemplate> 
<asp:Label runat="server" ID="lblTimeAtDestination"></asp:Label> 
</ItemTemplate> 
    <ItemStyle Width="80px" /> 
</telerik:GridTemplateColumn> 
 <telerik:GridTemplateColumn HeaderText="Info" UniqueName="TemplateColumn3">  
 <ItemTemplate> 
<asp:Label runat="server" ID="lblInfo"></asp:Label> 
 </ItemTemplate> 
<ItemStyle Width="50px" /> 
               
</telerik:GridTemplateColumn> 
 
</Columns> 
       
<DetailTables> 
<telerik:GridTableView AutoGenerateColumns="false" Name="Polls" DataKeyNames="GPSID" ShowFooter="false">  
 <ParentTableRelation> 
   <telerik:GridRelationFields DetailKeyField="JourneyID" MasterKeyField="JourneyID" /> 
</ParentTableRelation> 
<Columns> 
 
     
    <telerik:GridBoundColumn DataField="GPSDateTime" HeaderText="Time" DataFormatString="{0:dd/MM/yy HH:mm}">  
    <ItemStyle Width="100px" /> 
    </telerik:GridBoundColumn> 
    <telerik:GridTemplateColumn HeaderText="Location">  
    <ItemTemplate> 
      <asp:Label runat="server" ID="lblLocation"></asp:Label> 
    </ItemTemplate> 
    <ItemStyle Width="560px" /> 
    </telerik:GridTemplateColumn> 
    <telerik:GridTemplateColumn HeaderText="Speed">  
    <ItemTemplate> 
    <asp:Label runat="server" ID="lblSpeed"></asp:Label> 
    </ItemTemplate> 
    <ItemStyle Width="100px" /> 
    </telerik:GridTemplateColumn> 
   
    <telerik:GridTemplateColumn HeaderText="Total Time">  
    <ItemTemplate> 
    <asp:Label runat="server" ID="lblCumulativeTime"></asp:Label> 
    </ItemTemplate> 
     <ItemStyle Width="100px" /> 
    </telerik:GridTemplateColumn > 
    <telerik:GridTemplateColumn HeaderText="Total Distance">  
    <ItemTemplate> 
    <asp:Label runat="server" ID="lblCumulativeDistance"></asp:Label> 
    </ItemTemplate> 
     <ItemStyle Width="100px" /> 
    </telerik:GridTemplateColumn> 
      
</Columns> 
</telerik:GridTableView> 
 
</DetailTables>     
          
</MasterTableView> 
</telerik:RadGrid> 

Many thanks

2 Answers, 1 is accepted

Sort by
0
andieje
Top achievements
Rank 1
answered on 27 Jul 2009, 07:46 PM
Hello

I would be very grateful if someone could look at this post please

MAny thanks
0
Daniel
Telerik team
answered on 27 Jul 2009, 08:40 PM
Hello Andieje,

To export the table in the CommandTemplate, modify your code as shown below:
<table cellpadding="5" cellspacing="0" style="width: 200px"
    <colgroup> 
        <col /> 
        <col /> 
    </colgroup> 
    <tr> 
        <td style="width: 100px"
            No Journeys: 
        </td> 
        <td style="width: 100px"
            <asp:Label ID="lblNoJourneys" runat="server"></asp:Label> 

To avoid the misalignment you should hide the GridExpand column
protected void Button1_Click(object sender, EventArgs e) 
    RadGrid1.MasterTableView.GetColumn("ExpandColumn").HeaderStyle.Width = Unit.Pixel(1); 
    RadGrid1.MasterTableView.ExportToPdf(); 

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
andieje
Top achievements
Rank 1
Answers by
andieje
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or