I ran into this error and I wanted to post my work around to it. I was trying to add a popup warning to an existing edit button that kicked off an edit for a grid. The error I got is below.
Specified argument was out of the range of valid values.
Parameter name: ItemHierarchicalIndex
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: ItemHierarchicalIndex
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: ItemHierarchicalIndex]
Telerik.Web.UI.GridDataItemCollection.get_Item(String hierarchicalIndex) +113
Telerik.Web.UI.RadGrid.RaisePostBackEvent(String eventArgument) +3642
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981
What caused this error was the javascript I added to fire the grid_ItemCommand after the popup. It was firing off code inside the RadGrid Control before it ever got to my codebehind and this code was having the error.
Bad Code
<Telerik:RadScriptBlock ID=
"RadScriptBlock1"
runat=
"server"
>
<script language=
"javascript"
type=
"text/javascript"
>
function
confirmEdit() {
// This function prompts the user if they want to edit (Y/N).
<% If ShowPopup Then %>
radconfirm(
"The date selected is a prior period date, are you sure you want to edit the data for the date shown?"
, confirmCallBackFnEdit, 330, 100,
null
,
'Edit Receipt Noms (Y/N)'
);
<% Else %>
var
masterTable = $find(
"<%= RadGrid1.ClientID %>"
).get_masterTableView();
masterTable.fireCommand(
"Edit"
,
""
);
<% End If %>
}
function
confirmCallBackFnEdit(arg) {
if
(arg) {
var
masterTable = $find(
"<%= RadGrid1.ClientID %>"
).get_masterTableView();
masterTable.fireCommand(
"Edit"
,
""
);
}
}
</script>
</Telerik:RadScriptBlock>
To fix this error I renamed the CommandName I was looking for in the code behind Grid_ItemCommand from Edit to EditAll, changed the commandname on the button in HTML to EditAll and I changed the javascript to call EditAll. This bypassed the code inside the RadGrid control causing the error.
Good Code
<Telerik:RadScriptBlock ID=
"RadScriptBlock1"
runat=
"server"
>
<script language=
"javascript"
type=
"text/javascript"
>
function
confirmEdit() {
// This function prompts the user if they want to edit (Y/N).
<% If ShowPopup Then %>
radconfirm(
"The date selected is a prior period date, are you sure you want to edit the data for the date shown?"
, confirmCallBackFnEdit, 330, 100,
null
,
'Edit Receipt Noms (Y/N)'
);
<% Else %>
var
masterTable = $find(
"<%= RadGrid1.ClientID %>"
).get_masterTableView();
masterTable.fireCommand(
"EditAll"
,
""
);
<% End If %>
}
function
confirmCallBackFnEdit(arg) {
if
(arg) {
var
masterTable = $find(
"<%= RadGrid1.ClientID %>"
).get_masterTableView();
masterTable.fireCommand(
"EditAll"
,
""
);
}
}
</script>
</Telerik:RadScriptBlock>
It looks like a button CommandName of Edit should be treated like a reserved word until Telerik fixes this issue.