This is a migrated thread and some comments may be shown as answers.
RadGrid Export problem
12 Answers 476 Views
This is a migrated thread and some comments may be shown as answers.
Wenchao
Top achievements
Rank 1
Wenchao asked on 04 Dec 2008, 11:59 PM
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.

 

 

12 Answers, 1 is accepted

Sort by
0
Wenchao
Top achievements
Rank 1
answered on 05 Dec 2008, 01:08 AM
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?
0
Shinu
Top achievements
Rank 1
answered on 05 Dec 2008, 09:33 AM
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.
0
Accepted
Daniel
Telerik team
answered on 05 Dec 2008, 10:33 AM
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.
0
Wenchao
Top achievements
Rank 1
answered on 07 Dec 2008, 10:42 AM
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?
0
Wenchao
Top achievements
Rank 1
answered on 07 Dec 2008, 10:20 PM
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. 
0
Accepted
Shinu
Top achievements
Rank 1
answered on 08 Dec 2008, 07:22 AM
 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







        
         



0
Wenchao
Top achievements
Rank 1
answered on 09 Dec 2008, 09:48 AM
Thanks for that , those code are very helpful.
0
Bob
Top achievements
Rank 1
answered on 07 Jun 2010, 11:08 PM
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

0
Tsvetoslav
Telerik team
answered on 10 Jun 2010, 02:28 PM
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.
0
sayak
Top achievements
Rank 1
answered on 31 Aug 2010, 08:55 PM
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.
0
Daniel
Telerik team
answered on 31 Aug 2010, 09:48 PM
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
0
sayak
Top achievements
Rank 1
answered on 31 Aug 2010, 09:54 PM

Daniel,

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

 

Thanks,
Sayak

Tags
Grid
Asked by
Wenchao
Top achievements
Rank 1
Answers by
Wenchao
Top achievements
Rank 1
Shinu
Top achievements
Rank 1
Daniel
Telerik team
Bob
Top achievements
Rank 1
Tsvetoslav
Telerik team
sayak
Top achievements
Rank 1
Share this question
or