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

Item.selected not working while exporting grid to excel

3 Answers 122 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Atif
Top achievements
Rank 1
Atif asked on 11 Mar 2016, 11:59 AM

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)
            {
           }
}
}

3 Answers, 1 is accepted

Sort by
0
Atif
Top achievements
Rank 1
answered on 11 Mar 2016, 12:21 PM

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.

0
Konstantin Dikov
Telerik team
answered on 14 Mar 2016, 09:54 AM
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.
0
Atif
Top achievements
Rank 1
answered on 15 Mar 2016, 11:11 AM
Thank You so much Konstantin. IgnorePaging=false solved my issue. I should have read documentation first. MY BAD :)
Tags
General Discussions
Asked by
Atif
Top achievements
Rank 1
Answers by
Atif
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or