Excel export error while grid is in edit mode.

3 posts, 0 answers
  1. Christian
    Christian avatar
    2 posts
    Member since:
    Aug 2016

    Posted 30 Aug Link to this post

    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. Rumen
    Admin
    Rumen avatar
    12846 posts

    Posted 01 Sep Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Christian
    Christian avatar
    2 posts
    Member since:
    Aug 2016

    Posted 01 Sep in reply to Rumen Link to this post


    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.

Back to Top