
I am using radgrid and it is ajaxified by RadAjaxManager.I am using the exporttoexcel command item for exporting selected records from grid.After exporting the selected records I want to delete them from the grid.They are getting deleted from the DB but the grid is not getting refreshed.The grid.Rebind() is not working.Please guide me regarding this.
Thanks & Regards,
Manaswinee
10 Answers, 1 is accepted

protected void RGridImportedData_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToExcelCommandName)
{
if (RGridImportedData.SelectedItems.Count != 0)
{
foreach (GridDataItem item in RGridImportedData.MasterTableView.Items)
{
if (!item.Selected)
{
item.Visible =
false;
}
else
{
String id = item.GetDataKeyValue("OrderId").ToString();
if (id != null)
{
OrderController.DeleteIPurchaseRecord(id);
}
}
}
RGridImportedData.ExportSettings.ExportOnlyData =
true;
RGridImportedData.ExportSettings.OpenInNewWindow =
true;
RGridImportedData.Columns.FindByUniqueName(
"EditColumn").Display = false;
RGridImportedData.Columns.FindByUniqueName(
"DeleteColumn").Display = false;
RGridImportedData.Columns.FindByUniqueName(
"IsValid").Visible = false;
RGridImportedData.Columns.FindByUniqueName(
"Selected").Visible = false;
RGridImportedData.Columns.FindByUniqueName(
"LeadTime").Visible = false;
}
else
{
ShowAlertBox(
"Select records to be exported.");
e.Canceled =
true;
}
}
//RGridImportedData.EnableViewState = false;
////perform some actions here
//RGridImportedData.DataSource = null;
////call the Rebind() method after nullifying the data source
//RGridImportedData.Rebind();
//RGridImportedData.MasterTableView.ClearSelectedItems();
}
Hello, above is the code I am using for exporting selected records from radgrid.Kindly suggest if I am doing anything wrong.Any help is appreciated....
Thanks,
Manaswinee
The only way to refresh RadGrid after the export has been started is to save the output to a file and then cancel the export by refreshing the whole page (Response.Redirect).
The following blog post will be a good starting point for you:
How To: Export grid to PDF file and show the result using the window
Regards,
Daniel
the Telerik team

Thanks for your response. But the link given by you is not opening.Could you please elaborate a little as I am new to Telerik as well as to asp.net.Where should I do the changes,in client-side or in the same ItemCommand event of radgrid.
Best Regards,
Manaswinee

I am able to open the link provided by you.Here the 'path' is a constant string or something else.How could I get the path of the file.In my case the path could be anything as the user will select the location to save the file.
Best Regards,
Manaswinee
I attached a simple demo that uses the same approach as in the blog post. Your users will be able to click on the Download button and then eventually select the desired destination folder.
Best regards,
Daniel
the Telerik team

I need it ASAP

Here are the details of my problem
I am using RadAjaxManager on Master page and RadAjaxPanel on my child page. My RadGrid lies in the RadAjaxPanel of my child page.
My RadGrid has the button for "Export to Excel".
When user clicks on the Export to Excel button I have to rebind the same grid with other database and then call the ExportToExcel() method. I have disabled the Ajax as below on click of Export to Excel button click.
function onRequestStart(sender, args) {
if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0 ||
{
args.set_enableAjax(
false);
}
}
Now when user clicks on ExportToExcel button my file gets downloaded on the client end but the grid gets freezed under "loading.. " icon. I have to manually refresh the page to get to my page.
Please send me an example where we bind the grid to other datasource before exporting and after exporting, I can refresh my page.
The problem is most probably caused by the fact that you have double ajaxification which is something I would strongly recommend that you avoid in all cases. The best approach in this scenario would be to use RadAjaxManager and RadAjaxManagerProxy instead of mixing RadAjaxManager and RadAjaxPanel controls.
Kind regards,
Daniel
the Telerik team

Thanks for the reply. One more question.
I have HTML tags in my cell of RadGrid along with other data in my RadGrid
For eg. My one of the cell in radgrid contains this value "<html><tr><td>1 row</td></tr>\r\n<tr><td>1 row</td></tr> \r\n</html>".
Now when I call RadGrid.ExportToExcel() method. This data is not getting exported to Excel. All the rows above this cell are getting exported but this row and the rows following this row is not getting exported.
Please help !!!
RadGrid will not be able to export invalid HTML.
Regards,
Daniel
the Telerik team