CSV Export not exporting commanditem template.

9 posts, 0 answers
  1. Partha
    Partha avatar
    16 posts
    Member since:
    Jun 2011

    Posted 19 Jul 2011 Link to this post

    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?

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Jul 2011 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Partha
    Partha avatar
    16 posts
    Member since:
    Jun 2011

    Posted 20 Jul 2011 Link to this post

    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.
  5. Partha
    Partha avatar
    16 posts
    Member since:
    Jun 2011

    Posted 29 Aug 2011 Link to this post

    Princy,

    Any Progress on this issue?


    Thanks,
    Partha.
  6. Partha
    Partha avatar
    16 posts
    Member since:
    Jun 2011

    Posted 27 Sep 2011 Link to this post

    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.

  7. Nidhin
    Nidhin avatar
    2 posts
    Member since:
    Mar 2015

    Posted 12 Mar 2015 Link to this post

    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>
  8. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 17 Mar 2015 Link to this post

    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.

     
  9. Nidhin
    Nidhin avatar
    2 posts
    Member since:
    Mar 2015

    Posted 17 Mar 2015 in reply to Maria Ilieva Link to this post

    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
  10. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 19 Mar 2015 Link to this post

    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.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017