I'm working on an issue where some customers are reporting the following error when they run a report that displays results in a GridView
Error Message: Specified argument was out of the range of valid values. Parameter name: index
Source: System.Web
Stack Trace: at System.Web.UI.ControlCollection.get_item(Int32 index) at AppName.WebUIGridView.setNumberRecord() at System.Web.UI.Contro.PreRenderRecursiveInternal() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean
includeStagesAfterAsyncPoint)
As you can see this is pointing to a function called setNumberRecord()
Code for that function is here below:
Private Sub setNumberRecord()
' Set the ResultCount label.
Dim lblResult As Label = CType(GridManager1.Controls(0).FindControl("lblResultCount"), System.Web.UI.WebControls.Label)
Dim value As Integer = GridManager1.RowsCount
If (value > 0) Then
Dim sortDisplay As String = String.Empty
' Need to add a RequestData to work.
sortDisplay = GetSortColumnsDisplayNames()
If sortDisplay.Length Then
sortDisplay = " " & ResourceHelper.GetString("DatabasePagingGrid.SortedBy") & " " & sortDisplay
End If
lblResult.Text = String.Format("({0:N0} {1}{2})", value, ResourceHelper.GetString("DatabasePagingGrid.Records"), sortDisplay)
Else
lblResult.Text = ResourceHelper.GetString("DatabasePagingGrid.NoRecordsFound")
End If
End Sub
....................
I'm using a customer's DB to reproduce the issue and I can't. They also claim that it was working fine for the first two weeks they had the product running.
(not sure if this is a true claim but I'm just putting it out there)
Any clues? I've spent enough time trying to repro and have gotten nowhere so far.
Thanks for the suggestion but the report works fine for me. The data comes back and displays as expected.
Moreover, like I mentioned before, I'm using a copy of the customer's data to test this on my PC and it all works perfectly fine.
I can't debug code on their server but I did checked that I can reach the same type of data through other reports that do not use a GridView so a connection issue between Web Server and Database Server is out of the question.
Tell me about it! I've been trying to figure this one out for a couple of days now.
I'm going to assume that the copy of the DB the customer gave me is not identical to what they have in Prod. and run some queries on both sides to compare results, etc.
In the meantime, if anyone else has any other suggestions... that would be very much appreciated.
I've been wondering if this sudden error could also be related to some sort of Microsoft update?
The only line that I know can cause that Exception is the FindControl of the Label. In particular, the Controls(0). The Exception means element 0 wasn't found. In other words, there is nothing inside GridManager1.
What is GridManager1? If it is a GridView, that code never worked anyway, since GridView is made up of Rows, and there are no Controls findable directly on the GridView itself.
When is setNumberRecord called? If it can happen before DataBind, that would explain.
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
This code works fine for me and others. It is just three customers (companies) that are experiencing the error in their Production environment consistently.
The code you use will work properly, when it ensures there is data bound to GridView. Sometimes, if there is no data returned, this line will cause the error, because no control will be rendered if no data bound to GridView. You need to make a checking around
it.
I'll be adding the checks for an empty GridView right away and handling the errors this way.
However, this still leaves me at a loss as far as to diagnosing why this is occurring at a customer's site and not ours. While the checks are still necessary and good practice in general, I think it is important that we understand what's causing this problem
so we can address other pieces of code accordingly.
We have limited access to debug our code at a customer's site but if anyone has some clever ideas to do this and gather additional information, please feel free to share.
Zilliedream
Member
9 Points
5 Posts
ArgumentOutofRangeException when loading GridView
Feb 24, 2012 02:15 PM|LINK
Hi,
I'm working on an issue where some customers are reporting the following error when they run a report that displays results in a GridView
Error Message: Specified argument was out of the range of valid values. Parameter name: index
Source: System.Web
Stack Trace: at System.Web.UI.ControlCollection.get_item(Int32 index) at AppName.WebUIGridView.setNumberRecord() at System.Web.UI.Contro.PreRenderRecursiveInternal() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
As you can see this is pointing to a function called setNumberRecord()
Code for that function is here below:
Private Sub setNumberRecord() ' Set the ResultCount label. Dim lblResult As Label = CType(GridManager1.Controls(0).FindControl("lblResultCount"), System.Web.UI.WebControls.Label) Dim value As Integer = GridManager1.RowsCount If (value > 0) Then Dim sortDisplay As String = String.Empty ' Need to add a RequestData to work. sortDisplay = GetSortColumnsDisplayNames() If sortDisplay.Length Then sortDisplay = " " & ResourceHelper.GetString("DatabasePagingGrid.SortedBy") & " " & sortDisplay End If lblResult.Text = String.Format("({0:N0} {1}{2})", value, ResourceHelper.GetString("DatabasePagingGrid.Records"), sortDisplay) Else lblResult.Text = ResourceHelper.GetString("DatabasePagingGrid.NoRecordsFound") End If End Sub .................... I'm using a customer's DB to reproduce the issue and I can't. They also claim that it was working fine for the first two weeks they had the product running. (not sure if this is a true claim but I'm just putting it out there) Any clues? I've spent enough time trying to repro and have gotten nowhere so far.usman400
Contributor
3503 Points
721 Posts
Re: ArgumentOutofRangeException when loading GridView
Feb 24, 2012 02:47 PM|LINK
it seems that the grid is missing the data from its source
make sure the data is available use debug points in your application to check the code, variables and objects
at run time
Zilliedream
Member
9 Points
5 Posts
Re: ArgumentOutofRangeException when loading GridView
Feb 24, 2012 03:55 PM|LINK
Thanks for the suggestion but the report works fine for me. The data comes back and displays as expected.
Moreover, like I mentioned before, I'm using a copy of the customer's data to test this on my PC and it all works perfectly fine.
I can't debug code on their server but I did checked that I can reach the same type of data through other reports that do not use a GridView so a connection issue between Web Server and Database Server is out of the question.
usman400
Contributor
3503 Points
721 Posts
Re: ArgumentOutofRangeException when loading GridView
Feb 24, 2012 04:13 PM|LINK
then u should try at ur end, by providing no data for gridview
dude ur problem is quiet complicated !
Zilliedream
Member
9 Points
5 Posts
Re: ArgumentOutofRangeException when loading GridView
Feb 24, 2012 04:28 PM|LINK
Tell me about it! I've been trying to figure this one out for a couple of days now.
I'm going to assume that the copy of the DB the customer gave me is not identical to what they have in Prod. and run some queries on both sides to compare results, etc.
In the meantime, if anyone else has any other suggestions... that would be very much appreciated.
I've been wondering if this sudden error could also be related to some sort of Microsoft update?
usman400
Contributor
3503 Points
721 Posts
Re: ArgumentOutofRangeException when loading GridView
Feb 25, 2012 05:14 AM|LINK
I dont know if it helps you, couple of days ago, I had a similar error with grid view
I was uploading an excel file using FileUpload control, and reading the excel file to fill up the grid view
The excel file was in a shared folder, and whenever some one opened that file, I get the similar error you have mentioned
so I had to copy the file in the same folder, and then use the copied file in browse dialogue, and things worked fine
My point is, may be at customer side, the binidng mehcansim for your Grid, cant access the database
superguppie
All-Star
48225 Points
8679 Posts
Re: ArgumentOutofRangeException when loading GridView
Feb 27, 2012 02:43 PM|LINK
The only line that I know can cause that Exception is the FindControl of the Label. In particular, the Controls(0). The Exception means element 0 wasn't found. In other words, there is nothing inside GridManager1.
What is GridManager1? If it is a GridView, that code never worked anyway, since GridView is made up of Rows, and there are no Controls findable directly on the GridView itself.
When is setNumberRecord called? If it can happen before DataBind, that would explain.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
Zilliedream
Member
9 Points
5 Posts
Re: ArgumentOutofRangeException when loading GridView
Feb 27, 2012 07:22 PM|LINK
Hi.. Thanks for the reply.
GridManager1 is a Gridview.
SetNumberRecord() is called OnPreRender
This code works fine for me and others. It is just three customers (companies) that are experiencing the error in their Production environment consistently.
Qin Dian Tan...
All-Star
113532 Points
12480 Posts
Microsoft
Re: ArgumentOutofRangeException when loading GridView
Feb 28, 2012 07:54 AM|LINK
Hi,
The code you use will work properly, when it ensures there is data bound to GridView. Sometimes, if there is no data returned, this line will cause the error, because no control will be rendered if no data bound to GridView. You need to make a checking around it.
Thanks,
If you have any feedback about my replies, please contactmsdnmg@microsoft.com.
Microsoft One Code Framework
Zilliedream
Member
9 Points
5 Posts
Re: ArgumentOutofRangeException when loading GridView
Feb 28, 2012 01:34 PM|LINK
Thanks.
I'll be adding the checks for an empty GridView right away and handling the errors this way.
However, this still leaves me at a loss as far as to diagnosing why this is occurring at a customer's site and not ours. While the checks are still necessary and good practice in general, I think it is important that we understand what's causing this problem so we can address other pieces of code accordingly.
We have limited access to debug our code at a customer's site but if anyone has some clever ideas to do this and gather additional information, please feel free to share.