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

ExportToExcel Issue

2 Answers 41 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bhuvaneshwari
Top achievements
Rank 1
Bhuvaneshwari asked on 27 Nov 2014, 06:19 AM
The problem which i am facing is that i have an ExportToExcel image button in the grid.When i click on that , it is not asking for 'Open' or 'Save'  file in Excel. Instead the datas which are to be in the Excel is displayed in UI grid itself. The excel button is in the "GridFilteringItem" . Please note that the grid is placed within RadAjaxPanel.The code which I have used is

public void grid _ItemCreated(object sender, GridItemEventArgs e)
{
//if (e.Item is GridCommandItem)
//{
// Button btncmd = (e.Item as GridCommandItem).FindControl("ExportToExcelButton") as Button;
// (this.Master.FindControl("ScriptManagerMain") as System.Web.UI.ScriptManager).RegisterPostBackControl(btncmd);
//}
if (e.Item is GridHeaderItem)
{
GridHeaderItem headerItem = (GridHeaderItem)e.Item; // access the header row
Button btnUpdate = new Button(); // creating a new checkbox
btnUpdate.ID = "btnUpdate";
btnUpdate.Text = "Update Selected";
btnUpdate.OnClientClick = "ValidateCheckBox()";
btnUpdate.Click += new EventHandler(btnUpdateSelected_Click);
headerItem["Update"].Controls.Add(btnUpdate); // adding the checkbox to the control collection of the required cell
btnUpdate.Visible = true;
}
if (e.Item is GridFilteringItem)
{
ImageButton ExportToXLSButton = new ImageButton();
ExportToXLSButton.ID = "CustomExportToExcelButton";
ExportToXLSButton.AlternateText = ExportToXLSButton.ToolTip = "Export To Excel";
ExportToXLSButton.ImageUrl = "~/images/ExportToExcel.gif";
ExportToXLSButton.CommandName = RadGrid.ExportToExcelCommandName;
(e.Item as GridFilteringItem)["Update"].Controls.Add(ExportToXLSButton);
}
}

In ItemCommand

if (e.CommandName == RadGrid.ExportToExcelCommandName)
{
grid.ExportSettings.FileName = String.Format("X_{0}_to_{1}",
dtStart.SelectedDate.Value.ToString("MM-dd-yyyy"), dtEnd.SelectedDate.Value.ToString("MM-dd-yyyy"));
{
if (col.UniqueName != "X")
{
col.Visible = true;
}
}

grid.ExportSettings.ExportOnlyData = true;
grid.ExportSettings.IgnorePaging = true;
grid.ExportSettings.OpenInNewWindow = true;
grid.Rebind();
grid.MasterTableView.ExportToExcel();


I had even referred to the below links but i could not find any solution for this

http://www.telerik.com/forums/radgrid-export-to-excel-problem

http://www.telerik.com/help/aspnet-ajax/grid-export-with-ajax-enabled.html 

http://www.telerik.com/help/aspnet-ajax/ajax-exclude

Please help me out on this issue

Thanks

2 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 01 Dec 2014, 10:22 AM
Hi Bhuvaneshwari,

In order to export the grid you need to disable the ajax as described in the following help article. Generally you need to hook onRequestStart event and check whether the control that fires the request is the export to pdf button.

Regards,
Kostadin
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
Saurabh
Top achievements
Rank 1
answered on 02 Dec 2014, 09:44 AM
may me this will help. 
<script type="text/javascript">
         function onRequestStart(sender, args) {
             if (args.get_eventTarget().indexOf("ExportToPdf") >= 0) {
                 args.set_enableAjax(false);
             }
         }
    </script>


Tags
Grid
Asked by
Bhuvaneshwari
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Saurabh
Top achievements
Rank 1
Share this question
or