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

Excel Export - Specified argument was out of the range of valid values

5 Answers 605 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bill Wolff
Top achievements
Rank 1
Bill Wolff asked on 14 Jan 2015, 09:34 PM
I am getting this error when a user clicks Export on the radGrid heading:

Specified argument was out of the range of valid values.
Parameter name: index

[ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: index]
System.Web.UI.ControlCollection.get_Item(Int32 index) +11120470
Telerik.Web.UI.GridGroupPanel.get_MainTable() +54
Telerik.Web.UI.GridGroupPanel.OnPreRender(EventArgs e) +56

Any ideas? This also happens for PDF and Word exports. The grid uses an ObjectDataSource with EnablePaging true and a SortParameterName. Other grid functions like sorting, filtering, paging, and grouping work as advertised. The exports are setup in the markup like this:

    <ExportSettings Excel-Format="Html" Word-Format="Html" FileName="Batch"
        IgnorePaging="true" HideStructureColumns="true" OpenInNewWindow="true" ExportOnlyData="true">

5 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 19 Jan 2015, 12:17 PM
Hello Bill,

I am afraid that based on the provided information will be hard to pinpoint the reason for that behavior. Could you please provide your code declaration and the related code behind in order to investigate it further? Additionally could you disable the grouping and check out whether the issue remains?

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Bill Wolff
Top achievements
Rank 1
answered on 19 Jan 2015, 02:38 PM
I did some detailed testing and know what the problem is. I am using an ObjectDataSource with EnablePaging="true" and a SortParameterName. This provide the best performance for SQL queries which is my case are all parameterized stored procedures. When RadGrid does paging, it passes the PageSize as the maximumRows and the PageSize * PageIndex as the startRowIndex as expected. This works well.

However, when you apply a filter to a column, RadGrid passes 2147483647 as the maximumRows which is the highest value for an integer. This sort of makes sense, and it is easy to check for this in a stored procedure and return all rows. The entire table is returned and RadGrid uses a LINQ expression on the row collection to display the filtered rows.

The next problem was export to Excel, PDF, and Word. Oddly enough, when RadGrid does an export, it passes 0 as the maximumRows which my stored procedure was interpreting as no rows. I added a test for 0 to the stored proc and now return all rows so the export is working once again. If a filter is applied, the LINQ expression is honored and the export has only the filtered dat in it.

I still can't get export to work at all with ShowGroupPanel="True". Any clues?







0
Bill Wolff
Top achievements
Rank 1
answered on 19 Jan 2015, 06:57 PM
I did some more testing. If you set ShowGroupPanel="True" to enable grouping, any export button still causes the Index out of range error. The ObjectDataSource is called with 0 as the maximumRows and 0 as the startPageIndex. This should return all possible rows.The error could be in the filter LINQ expression but the same error occurs with and without a filter. There is something in your export code that gets confused by the grouping.

Is there a simple way to turn off grouping prior to export but have it still work for the user?
0
Accepted
Kostadin
Telerik team
answered on 22 Jan 2015, 10:24 AM
Hello Bill,

A possible solution is to disable the grouping when export to Excel command is fired. This way the grouping will be removed only the export file and will not effect the rendered RadGrid. If you are using the built-in buttons then you can hook OnItemCommand event handler and disable the grouping as demonstrated below.
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.ExportToExcelCommandName)
    {
        RadGrid1.MasterTableView.GroupByExpressions.Clear();
        if (!RadGrid1.ExportSettings.IgnorePaging)
            RadGrid1.Rebind();
    }
}


Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Bill Wolff
Top achievements
Rank 1
answered on 22 Jan 2015, 05:18 PM
That helped and we can mark this one as answered. I had to set 

RadGrid1.ShowGroupPanel = false; 

instead of 

RadGrid1.MasterTableView.GroupByExpressions.Clear()

in the code above.
Tags
Grid
Asked by
Bill Wolff
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Bill Wolff
Top achievements
Rank 1
Share this question
or