Item.selected not working while exporting grid to excel

4 posts, 0 answers
  1. Atif
    Atif avatar
    18 posts
    Member since:
    Jul 2015

    Posted 11 Mar Link to this post

    Hello,

    I am trying to export only selected rows in excel but while exporting, item.selected is always returning false in ItemCommand, GridExporting

    case "ExportToExcel":
                        e.Canceled = true;
                        GridDataItem item3 = (GridDataItem)e.Item;
                        if (item3.Selected)
                        {
                            string Str = item3["ITEM_ID"].Text.ToString();
                        }
                        break;

    In  GridExporting

    protected void rgDeviceApproval_GridExporting(object sender, GridExportingArgs e)
        { foreach (GridDataItem item in this.rgDeviceApproval.MasterTableView.Items)
            {
     
                if (item.selected)
                {
               }
    }
    }

  2. Atif
    Atif avatar
    18 posts
    Member since:
    Jul 2015

    Posted 11 Mar Link to this post

    In ExportToExcel,  Item.selected is working but not in grid exporting Event.

    Is there any way to update excel output in item command. I am changing excel output in grid exporting by replacing html in e.exportoutput, but unable to do it in item command.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1795 posts

    Posted 14 Mar Link to this post

    Hi Atif,

    If you have enabled paging with IgnorePaging export property set to "true", the selected items will be cleared within the OnGridExported event, because the control will rebind in order to retrieve all items before the export. If the IgnorePaging is set to "false", you can set the Visible property of the non-selected items:
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.ExportToExcelCommandName)
        {
            foreach (GridDataItem item in RadGrid1.Items)
            {
                if (!item.Selected)
                {
                    item.Visible = false;
                }
            }
        }
    }

    For more information regarding the export functionality, please refer to our documentation: 
    Hope this helps.


    Regards,
    Konstantin Dikov
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  5. Atif
    Atif avatar
    18 posts
    Member since:
    Jul 2015

    Posted 15 Mar Link to this post

    Thank You so much Konstantin. IgnorePaging=false solved my issue. I should have read documentation first. MY BAD :)
Back to Top