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

Excel export error while grid is in edit mode.

2 Answers 37 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 30 Aug 2016, 08:32 PM

Hi,

I'm getting an error when a user clicks on the export to excel button while the grid is edit or insert mode. Is there a quick way to address this or do i have to check for the grid's state and disable/enable the button?

2 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 01 Sep 2016, 07:04 AM
Hello Christian,

Can you send the whole error along with the stack trace so that we can examine it? You can make a screenshot of the error and attach it.

Best regards,
Rumen
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Christian
Top achievements
Rank 1
answered on 01 Sep 2016, 02:39 PM


I found a workaround for anyone interested:
 
1- wire the ItemCommand, ItemInserted and ItemUpdated events in your grid:
        OnItemCommand="RadGrid1_ItemCommand" OnItemInserted="RadGrid1_ItemInserted" OnItemUpdated="RadGrid1_ItemUpdated"
        
2- Handle the events to prevent excel exporting while the grid does not contain data:

protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (Session["cancelExcelExport"] == null)
            {
                Session["cancelExcelExport"] = false;
            }
            
            if (e.CommandName == RadGrid.EditCommandName || e.CommandName == RadGrid.InitInsertCommandName)
            {
                Session["cancelExcelExport"] = true;    
            }

            if (e.CommandName == RadGrid.CancelCommandName)
            {
                Session["cancelExcelExport"] = false;
            }

            if (e.CommandName == RadGrid.ExportToExcelCommandName && (bool)Session["cancelExcelExport"] == true)
            {
                e.Canceled = true;
            }
        }
        protected void RadGrid1_ItemInserted(object source, GridInsertedEventArgs e)
        {
            Session["cancelExcelExport"] = false;
        }
        protected void RadGrid1_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e)
        {
            Session["cancelExcelExport"] = false;
        }

 

 

 

Hope this helps someone.

Tags
Grid
Asked by
Christian
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Christian
Top achievements
Rank 1
Share this question
or