RadGrid Export problem

13 posts, 2 answers
  1. Wenchao
    Wenchao avatar
    21 posts
    Member since:
    Nov 2008

    Posted 04 Dec 2008 Link to this post

    hi
    I come across some problem with the exporting. The issue is that I can't export all the record in the grid even I set "IgnorePaging"  to true; it only save the current page. The RadGrid is on a updatepanel, and the event for imagebutton click as follows

     

    protected void ImgbtExcel_Click(object sender, ImageClickEventArgs e)

    {

    RadGridEmp.ExportSettings.ExportOnlyData =

    true

     

     

    RadGridEmp.ExportSettings.IgnorePaging =

    true;

     

     

    RadGridEmp.ExportSettings.OpenInNewWindow =

    true;  

     

     

    RadGridEmp.MasterTableView.ExportToExcel();

    }

    everytime it only save the current page.

     

     

  2. Wenchao
    Wenchao avatar
    21 posts
    Member since:
    Nov 2008

    Posted 04 Dec 2008 Link to this post

    I tried to narrow down the factor for this issue.
    So I removed all the update panel and also the tabstrip only RadGrid and a image button, but I got the same issue.
    BTW, I assign the datasource in the code not using sql datasource, don't know whether that's the issue.
    and the setting is:

     

    <exportsettings

     

     

    exportonlydata="True" filename="EmployeeDetails" ignorepaging="True"

     

     

    openinnewwindow="True"><Excel Format="ExcelML" />

     

     

    </exportsettings>

     


    any one knows about this problem?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 05 Dec 2008 Link to this post

    Hi,

    I tried exporting with IgnorePaging property set to true and it is working as expected. One another suggestion will be to disable paging in the click event of the Export button so that the entire Grid data will get exported.

    CS:
     protected void LinkButton1_Click(object sender, EventArgs e) 
        { 
            RadGrid1.MasterTableView.AllowPaging = false
            RadGrid1.MasterTableView.Rebind(); 
            RadGrid1.ExportSettings.OpenInNewWindow = true
            RadGrid1.MasterTableView.ExportToExcel(); 
        } 

    Regards
    Shinu.
  5. Answer
    Daniel
    Admin
    Daniel avatar
    4945 posts

    Posted 05 Dec 2008 Link to this post

    Hello Wenchao,

    Please let us know how you populated your RadGrid. I suggest you consider adding a NeedDataSource handler and bind the control inside this handler.

    More information about NeedDataSource:
    Advanced data-binding w/NeedDataSource

    Let us know if you need further assistance.

    Best regards,
    Daniel
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Wenchao
    Wenchao avatar
    21 posts
    Member since:
    Nov 2008

    Posted 07 Dec 2008 Link to this post

    hi all,
    thanks for the code and suggestions.
    Before for some reason I binded the datasource in Page_Prerender event and it's not working for the "export all",now I bind the radgrid datasoure in the needdatasource event,and it's working.
    But as I used an updatepanel which contains the radgrid to do an Asynchronize postback triggered by a button outside the panel, when the page loads it did not call the  needdatasource event to load the new datasource, so I have to rebind it every time on the Page_load event, but this doesn't seem to be a right way. do  I need to chage the update panel to Asynchronize manager to do the job?
  7. Wenchao
    Wenchao avatar
    21 posts
    Member since:
    Nov 2008

    Posted 07 Dec 2008 Link to this post

    hi,
    I have another question about the RadGrid Export, is there any way for doing export process on the client side, I saw the functions  on the client side for exporting 
    - client-side
    o ExportToExcel(fileName)
    o ExportToWord(fileName)

    but there are no samples for that, and I 'm not familiar with Javascript, so any sample code would be great, thanks in advance. 
  8. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 08 Dec 2008 Link to this post

     i Wenchao ,

    The exporting feature of the control work with regular postbacks only.The reason is the grid prepares additional information when performing export operation (available on postback). When the action is performed through asynchronous requests, this information can not be passed through the XMLHttpObject - that is why the communication between the browser and the server fails. Go through the following help article for getting more details on this regard.
    Export from ajaxified grid

    Try the following code snippet to export the Grid from the client side.

    JS:

    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
                <script type="text/javascript">
                function ExportGrid()
                {
                    var masterTable = $find("<%=RadGrid1.ClientID %>").get_masterTableView();
                    masterTable.exportToExcel();
                }
                </script>
                </telerik:RadCodeBlock>  




    ASPX:

      <telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" AllowPaging="True"
                    AllowSorting="True" OnNeedDataSource="RadGrid1_NeedDataSource">
                    <ClientSettings>
                        <Selecting AllowRowSelect="true" />
                    </ClientSettings>
                </telerik:RadGrid>
           
            <input id="Button1" type="button" value="Export" onclick="ExportGrid()" />



    Thanks
    Shinu







            
             



  9. Wenchao
    Wenchao avatar
    21 posts
    Member since:
    Nov 2008

    Posted 09 Dec 2008 Link to this post

    Thanks for that , those code are very helpful.
  10. Bob
    Bob avatar
    28 posts
    Member since:
    Jul 2009

    Posted 07 Jun 2010 Link to this post

    Hello Telerik Team,

    I have a problem with Exporting.

    1. I am inside of a Web part (which has an MS Update Panel)
    2. Inside the MS Update Panel, I have a data grid with client side data binding using ADO.Net data service
    3. I register the export buttons as Postback Controls using the following code

            private void RegisterExportButtonsAsPostbackControls() 
            { 
                foreach (string exportID in new[] { "Pdf""Excel""Csv""Word" }) 
                { 
     
                    Control expControl = FindNamedControl(mGrid, "ExportTo" + exportID + "Button"); 
                    if (expControl != null
                    { 
                        ScriptManager.GetCurrent(Page).RegisterPostBackControl(expControl); 
                    } 
                } 
     
            } 
     

    4. I have an OnCommand client side event attached to the Grid
    5. When the Export button is pressed, my OnCommand client event fires and I get a CommandName = "ExportToExcel"
    6. I make sure args.set_cancel(false) is executed and I return from the event handler
    7. Nothing Happens.

    The HTML code associated with the Excel button renders on the browser as follows

    <input type="submit" name="ctl00$WebPartManager$WorkAreaWebPart$MainControl$RestrictionsGrid$ctl00$ctl02$ctl00$ExportToExcelButton" value=" " onclick="if(!$find('ctl00_WebPartManager_WorkAreaWebPart_MainControl_RestrictionsGrid_ctl00').exportToExcel()) return false;" id="ctl00_WebPartManager_WorkAreaWebPart_MainControl_RestrictionsGrid_ctl00_ctl02_ctl00_ExportToExcelButton" title="Export to Excel" class="rgExpXLS" / 

    The onclick event seems to be wrapped with an 'if' statement and when I step thru with Chrome debugger, it seems that even though I set args.set_cancel(false), when the function returns, some other object seems to have _cancel set to true and the postback does not happen


    Thoughts?

    Bob

  11. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 10 Jun 2010 Link to this post

    Hello Bob,

    Exporting from a client-side data-bound grid is not a scenario supported by the RadGrid control.

    Best wishes,
    Tsvetoslav
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  12. sayak
    sayak avatar
    23 posts
    Member since:
    Jun 2007

    Posted 31 Aug 2010 Link to this post

    Hi All,
      I have a rad grid in an rad ajax panel, and a button that exports the grid to excel. I have mentioned the Filename of the excel file.

    When I click the button, a popup opens up with options to Open, Save or Cancel.

    Save works fine with the proper name of file, but if I choose open, I get a weird name.

     GridSalary.ExportSettings.FileName = HttpUtility.UrlEncode("Test", System.Text.Encoding.UTF8);

    Open click gives me this name : %54%65%73%74.xls

    This is happening only in IE 7, Firefox there is no issue.

    I am using 2009 Q2 rad controls.


    Please help.
  13. Daniel
    Admin
    Daniel avatar
    4945 posts

    Posted 31 Aug 2010 Link to this post

    Hello Sayak,

    Give this approach a try. It will override the filename encoding.
    protected void RadGrid1_GridExporting(object sender, GridExportingArgs e)
    {
        if (e.ExportType == ExportType.Excel)
        {
            string fileName = RadGrid1.ExportSettings.FileName + "." + RadGrid1.ExportSettings.Excel.FileExtension;
            Response.ClearHeaders();
            Response.ContentType = "application/vnd.ms-excel";
     
            Response.AddHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
            Response.Write(e.ExportOutput);
        }
    }

    Best regards,
    Daniel
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  14. sayak
    sayak avatar
    23 posts
    Member since:
    Jun 2007

    Posted 31 Aug 2010 Link to this post

    Daniel,

      Kudos to you. It worked like a charm. Thanks a ton for your prompt help with this.

     

    Thanks,
    Sayak

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