Hi Kalai,
My first advise is to use Advanced Data Binding with NeedDataSource event to bind data to the Grid. We also have an article addressing this: How to bind RadGrid properly on server-side
Also, when clicking on the export button, that fires the ExportCommand, which can be captured in the ItemCommand Event. If this event is not canceled, the command will happen any ways. Calling the ExportToExcel() method inside the ItemComand will basically tell the grid to export during exporting.
Once the Binding is done, all you need to do in the command item is count the Grid's items and if the number is more than 5 cancel the command.
Example:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
if(e.CommandName == RadGrid.ExportToExcelCommandName)
{
RadGrid1.AllowPaging = false;
RadGrid1.Rebind();
var rowCount = RadGrid1.Items.OfType<GridDataItem>().Count();
if(rowCount > 5)
{
e.Canceled = true;
}
}
}
I hope this will help resolve the issue.
Kind regards,
Attila Antal
Progress Telerik
Get
quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers.
Learn More.