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

CSV Export not exporting commanditem template.

8 Answers 153 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Partha
Top achievements
Rank 1
Partha asked on 19 Jul 2011, 05:26 AM
Hello All,

Presently I am having a telerik radgrid with a commanditem template above the grid header for some extra  information.But the problem is that while exporting to CSV , the header information inside the commandItem template is not being exported.However the export is working just fine with PDF and Excel .Here is the code I am using.


 <telerik:RadGrid ID="ModifiedContentsReportGrid" runat="server" AutoGenerateColumns="false"
                AllowSorting="true" AllowPaging="true" EnableOutsideScripts="true" PagerStyle-Mode="NextPrevAndNumeric"
                ShowFooter="true" OnItemCreated="ModifiedContentsReportsGrid_OnItemCreated" Title="Modified Content Report"
                Height="100%" ExportSettings-ExportOnlyData="false" 
                EnableViewState="true">
                <ItemStyle BackColor="transparent" />
                <AlternatingItemStyle BackColor="#F9F9F9" />
                <ExportSettings OpenInNewWindow="true" FileName="Modified Content Report" ExportOnlyData="false" >
                    <Pdf PaperSize="A4" AllowPrinting="true" PageBottomMargin="10px" PageTopMargin="25px"
                        PageHeaderMargin="0px" PageLeftMargin="10px" PageRightMargin="10px" PageTitle="Modified Content Report" />
                </ExportSettings>
                <HeaderStyle HorizontalAlign="Center" />
                <ClientSettings>
                    <Scrolling UseStaticHeaders="true" />
                </ClientSettings>
                <MasterTableView Width="100%" CommandItemDisplay="Top" CommandItemStyle-HorizontalAlign="Right"
                    TableLayout="Fixed">
                    <CommandItemTemplate>
                        <asp:Literal runat="server"><b>Account Name :</b></asp:Literal>
                        <asp:Label ID="lblClientName" runat="server" /><br />
                        <asp:Literal runat="server"><b>Report generated on :</b></asp:Literal>
                        <asp:Label ID="lblGenerateDate" runat="server" /><br />
                        <asp:Literal runat="server"><b>Date Range :</b></asp:Literal>
                        <asp:Label ID="lblDateRange" runat="server" />
                    </CommandItemTemplate>
                    <Columns>
                        <telerik:GridBoundColumn DataField="Name" SortExpression="Name" HeaderText="Content File"
                             SortAscImageUrl="/Images/SortAsc.gif" SortDescImageUrl="/Images/SortDesc.gif"
                            ItemStyle-Width="30%">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Location" SortExpression="Location" HeaderText="Location"
                            SortAscImageUrl="/Images/SortAsc.gif" SortDescImageUrl="/Images/SortDesc.gif"
                            ItemStyle-Width="30%">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Project/Folder" SortExpression="Project/Folder"
                            HeaderText="Project/Folder" SortAscImageUrl="/Images/SortAsc.gif" SortDescImageUrl="/Images/SortDesc.gif"
                            ItemStyle-Width="10%">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Document" SortExpression="Document" HeaderText="Document"
                            SortAscImageUrl="/Images/SortAsc.gif" SortDescImageUrl="/Images/SortDesc.gif"
                            ItemStyle-Width="10%">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Section" SortExpression="Section" HeaderText="Section"
                            SortAscImageUrl="/Images/SortAsc.gif" SortDescImageUrl="/Images/SortDesc.gif"
                            ItemStyle-Width="10%">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="JobNumber" SortExpression="JobNumber" HeaderText="Job Number"
                            SortAscImageUrl="/Images/SortAsc.gif" SortDescImageUrl="/Images/SortDesc.gif"
                            ItemStyle-Width="10%">
                        </telerik:GridBoundColumn>
                    </Columns>
                    <NoRecordsTemplate>
                        <asp:Literal runat="server">
                    No records to display.</asp:Literal>
                    </NoRecordsTemplate>
                </MasterTableView>
                <PagerStyle Mode="NextPrevAndNumeric" />
            </telerik:RadGrid>

Can anyone provide some some inputs or solution to this problem?

8 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 Jul 2011, 05:43 AM
Hello Partha,

After examining your code, I suppose you are using SimpleDataBinding which does not support complex scenarios like paging, exporting etc. Make sure that you are binding the RadGrid with Advanced Data-binding using NeedDataSource event. Check the following help documentation which explains more about this.
Advanced Data-binding (using NeedDataSource event).

Thanks,
Princy.
0
Partha
Top achievements
Rank 1
answered on 20 Jul 2011, 05:29 AM
Princy,

Actually with the present databinding I can export and pagination is also working fine . But only when exporting to CSV this problem arises(export with pdf and excel is working fine).


Thanks,
Partha.
0
Partha
Top achievements
Rank 1
answered on 29 Aug 2011, 10:13 AM
Princy,

Any Progress on this issue?


Thanks,
Partha.
0
Partha
Top achievements
Rank 1
answered on 27 Sep 2011, 07:09 AM
Can anyone provide any solution to this problem.Here is the code I am using:


 <telerik:RadGrid ID="ModifiedContentsReportGrid" runat="server" AutoGenerateColumns="false"
                AllowSorting="true" AllowPaging="true" EnableOutsideScripts="true" PagerStyle-Mode="NextPrevAndNumeric"
                ShowFooter="true" OnItemCreated="ModifiedContentsReportsGrid_OnItemCreated" Title="Modified Content Report"
                Height="100%" ExportSettings-ExportOnlyData="false" 
                EnableViewState="true">
                <ItemStyle BackColor="transparent" />
                <AlternatingItemStyle BackColor="#F9F9F9" />
                <ExportSettings OpenInNewWindow="true" FileName="Modified Content Report" ExportOnlyData="false" >
                    <Pdf PaperSize="A4" AllowPrinting="true" PageBottomMargin="10px" PageTopMargin="25px"
                        PageHeaderMargin="0px" PageLeftMargin="10px" PageRightMargin="10px" PageTitle="Modified Content Report" />
                </ExportSettings>
                <HeaderStyle HorizontalAlign="Center" />
                <ClientSettings>
                    <Scrolling UseStaticHeaders="true" />
                </ClientSettings>
                <MasterTableView Width="100%" CommandItemDisplay="Top" CommandItemStyle-HorizontalAlign="Right"
                    TableLayout="Fixed">
                    <CommandItemTemplate>
                        <asp:Literal runat="server"><b>Account Name :</b></asp:Literal>
                        <asp:Label ID="lblClientName" runat="server" /><br />
                        <asp:Literal runat="server"><b>Report generated on :</b></asp:Literal>
                        <asp:Label ID="lblGenerateDate" runat="server" /><br />
                        <asp:Literal runat="server"><b>Date Range :</b></asp:Literal>
                        <asp:Label ID="lblDateRange" runat="server" />
                    </CommandItemTemplate>
                    <Columns>
                        <telerik:GridBoundColumn DataField="Name" SortExpression="Name" HeaderText="Content File"
                             SortAscImageUrl="/Images/SortAsc.gif" SortDescImageUrl="/Images/SortDesc.gif"
                            ItemStyle-Width="30%">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Location" SortExpression="Location" HeaderText="Location"
                            SortAscImageUrl="/Images/SortAsc.gif" SortDescImageUrl="/Images/SortDesc.gif"
                            ItemStyle-Width="30%">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Project/Folder" SortExpression="Project/Folder"
                            HeaderText="Project/Folder" SortAscImageUrl="/Images/SortAsc.gif" SortDescImageUrl="/Images/SortDesc.gif"
                            ItemStyle-Width="10%">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Document" SortExpression="Document" HeaderText="Document"
                            SortAscImageUrl="/Images/SortAsc.gif" SortDescImageUrl="/Images/SortDesc.gif"
                            ItemStyle-Width="10%">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Section" SortExpression="Section" HeaderText="Section"
                            SortAscImageUrl="/Images/SortAsc.gif" SortDescImageUrl="/Images/SortDesc.gif"
                            ItemStyle-Width="10%">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="JobNumber" SortExpression="JobNumber" HeaderText="Job Number"
                            SortAscImageUrl="/Images/SortAsc.gif" SortDescImageUrl="/Images/SortDesc.gif"
                            ItemStyle-Width="10%">
                        </telerik:GridBoundColumn>
                    </Columns>
                    <NoRecordsTemplate>
                        <asp:Literal runat="server">
                    No records to display.</asp:Literal>
                    </NoRecordsTemplate>
                </MasterTableView>
                <PagerStyle Mode="NextPrevAndNumeric" />
            </telerik:RadGrid>

Thanks,
Partha.

0
Nidhin
Top achievements
Rank 1
answered on 12 Mar 2015, 01:31 PM
Hi All,
I am also facing the same problem while exporting to CSV from rad grid. Is there any way to export these to csv?
    <CommandItemTemplate>
                        <asp:Literal runat="server"><b>Account Name :</b></asp:Literal>
                        <asp:Label ID="lblClientName" runat="server" /><br />
                        <asp:Literal runat="server"><b>Report generated on :</b></asp:Literal>
                        <asp:Label ID="lblGenerateDate" runat="server" /><br />
                        <asp:Literal runat="server"><b>Date Range :</b></asp:Literal>
                        <asp:Label ID="lblDateRange" runat="server" />
    </CommandItemTemplate>
0
Maria Ilieva
Telerik team
answered on 17 Mar 2015, 10:47 AM
Hi Nidhin,

Note that exporting the CommandItemTemplate  in CSV file is not a supported scenario. The CSV exporting logic is tracing all the Grid cells and get their values to present them as comma separated values. However the CommandItemTemplate does not include such data, that can be presented as comma separated values and it is not included in this logic.

Regards,
Maria Ilieva
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Nidhin
Top achievements
Rank 1
answered on 17 Mar 2015, 10:57 AM
Hi Maria,
Thank you for your time.
Is there any way I could read the CommandItemTemplate contents and  Groups into a string from the radgrid? Once I get those values in string, then I can make new function to export as CSV.

Thanks in advance
0
Maria Ilieva
Telerik team
answered on 19 Mar 2015, 03:13 PM
Hello Nidhin,

 You can use the approach below for accessing the controls in the CommandItemTemplate and get their string representation:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
   {
       if (e.CommandName == "Export")
       {
           GridCommandItem cmdItem = (GridCommandItem)RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0];
           LinkButton linkBtn1 = (LinkButton)cmdItem.FindControl("LinkButton1");
           string txt = linkBtn1.Text;
           
        }
   }

I hope this helps.

Regards,
Maria Ilieva
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Partha
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Partha
Top achievements
Rank 1
Nidhin
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or