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

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

9 Answers 1009 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anton
Top achievements
Rank 1
Anton asked on 19 Nov 2008, 09:15 AM
Got problem with the delete comand in grid.
Scenario: after page loading push the standard button "Delete" at the GridButtonColumnType(buttonColumn.CommandName = "Delete") of any grid item.
Error description:

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.GridItemCollection.get_Item(String hierarchicalIndex) +103
Telerik.Web.UI.GridDataItemCollection.get_Item(String hierarchicalIndex) +37
Telerik.Web.UI.RadGrid.RaisePostBackEvent(String eventArgument) +4133
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

The strange is:
If I comment the defined in OnInit() handler lines
            dataGrid.ClientSettings.ClientEvents.OnGridCreated = "GridCreated"
            dataGrid.ClientSettings.ClientEvents.OnRowClick = "RowClick"
            dataGrid.ClientSettings.ClientEvents.OnCommand = "GridCommand"

No error returned. Everything is fine...
But the current definition of client handlers is:
                    function RowClick(sender, eventArgs) {  
 
                    }  
 
                    function GridCommand(sender, args) {  
 
                    }  
 
                    function GridCreated(sender, eventArgs) {  
 
                    }  
Please, suggest me to the way of solving the problem.


9 Answers, 1 is accepted

Sort by
0
Anton
Top achievements
Rank 1
answered on 19 Nov 2008, 11:06 AM
In addition...
If I place lines
            dataGrid.ClientSettings.ClientEvents.OnGridCreated = "GridCreated";  
            dataGrid.ClientSettings.ClientEvents.OnRowClick = "RowClick";  
            dataGrid.ClientSettings.ClientEvents.OnCommand = "GridCommand";  

to OnPreRender handler everything works fine, but only for the first delete command.
Attempt of second removal of any item cause the same error...

Any ideas?


0
Anton
Top achievements
Rank 1
answered on 19 Nov 2008, 11:27 AM
In Addition 2...
Actually, delete column created programmatically in my case in Page_Init().
        public void AddDeleteColumn() 
        { 
            GridButtonColumn buttonColumn = new GridButtonColumn(); 
            buttonColumn.ButtonType = GridButtonColumnType.ImageButton; 
            buttonColumn.UniqueName = "DeleteCol"
            buttonColumn.CommandName = "Delete"
            buttonColumn.Text = "Delete"
            buttonColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center; 
            buttonColumn.ItemStyle.CssClass = "MyImageButton"
            dataGrid.MasterTableView.Columns.Add(buttonColumn); 
        } 

If I use instead of programmatic creation
            dataGrid.AutoGenerateDeleteColumn = true
 

the error disappears and all works fine.

So, what's problem with programmatically created column? What evend should I use for the delete column creation to prevent errors?
0
Anton
Top achievements
Rank 1
answered on 20 Nov 2008, 11:15 AM
Guys, please, give me at least a direction to research )
According to the documented event's stack:
On edit/update/insert/delete action or paging/sorting/grouping/filtering operation
For each Item:
    ItemCreated 
Page.Load
Grid_Instance.ItemCommand

Error rises during event Page.Load. ItemCommand already doesn't rises.
What can I do to find the reason of error described above?

0
Sebastian
Telerik team
answered on 20 Nov 2008, 11:24 AM
Hi Anton,

Do you attempt to create part of the grid columns statically and the rest programmatically from the code-behind of the page? Note that RadGrid does not support mixing declarative grid columns with grid columns added dynamically at runtime. You should either create all the columns in the grid programmatically, or else define them all in the ASPX file.

Review this help article which explains the basic concepts for creating RadGrid dynamically.

Kind regards,
Stephen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Anton
Top achievements
Rank 1
answered on 20 Nov 2008, 11:37 AM
Hi Stephen ,

I'm do not use static column declaration.
All of columns creates programmatically from the code-behind of the page in Page_Init handler.
The mysticism is that operation from auto-generated column works fine while from programmatically created column failed.
Even when both of these columns placed to grid together.
In both cases command the same - standard "Delete".

0
Sebastian
Telerik team
answered on 20 Nov 2008, 11:44 AM
Hello Anton,

Can you please confirm that the grid instance itself is generated in the PageInit handler as well and added to the Controls collection of a placeholder control as illustrates in the help topic? If the issue persists, please isolate a subset of your project and send it enclosed to a formal support ticket. We will examine it locally and will get back to you with more info on the subject.

Kind regards,
Stephen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Mohamed
Top achievements
Rank 1
answered on 01 Jul 2013, 12:06 PM

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




Here my code snippet please help me.It happen only when i try to sort
ASPX


<%@ Page Language="C#" MasterPageFile="~/Admin/Admin.master" AutoEventWireup="true"
    CodeFile="ApprovalGroup.aspx.cs" Inherits="ZeroChaos.ZCWeb.clsApprovalGroup"
     EnableEventValidation="false" %>

<%@ Register Src="~/UserControls/Menus/UCClientSetupMenu.ascx" TagName="ClientSetupMenu"
    TagPrefix="UCClientSetupMenu" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<%@ Register Assembly="ZCWebControls" Namespace="ZeroChaos.ZCWeb.ZCWebControls" TagPrefix="ext" %>
<%@ Register Assembly="ZCWebControls" Namespace="ZeroChaos.ZCWeb.ZCWebControls" TagPrefix="reduc" %>
<%@ Register Src="~/Admin/Controls/ClientNameUserControl.ascx" TagName="ClientNameUserControl"
    TagPrefix="UCClientNameUserControl" %>
<asp:Content ID="Content2" ContentPlaceHolderID="contplhDynamic" runat="Server">
    <link href="<%= Application["CSSPath"]%>CommonDeveloper.css" rel="stylesheet" type="text/css" />
    <asp:LinqDataSource ID="ListLinqDataSource" EnableObjectTracking="false"   TableName="VIEW_ApprovalGroups"
        ContextTypeName="DbHelper.Linq.ListPageDataContext"
        OnContextCreating="OnListDataContextCreating" OrderBy="ApprovalGroupName" Where="ClientID=@ClientID"
         runat="server">
        <WhereParameters>
            <asp:SessionParameter DefaultValue="0" SessionField="ClientID" Name="ClientID" Type="Int32" />
        </WhereParameters>
    </asp:LinqDataSource>
    <div id="Div1" class="dhtmltooltip" runat="server">
    </div>
    
    <script language="javascript" type="text/javascript">

    function ValidateSubmit()
        {        
            var chkCollection = document.getElementsByTagName('input');

            var blnChecked = false;
            var strControlPrefix = 'ctl00_contplhDynamic_';
            for(var _intLoop=0;_intLoop<chkCollection.length;_intLoop++)
            {                   
                if(chkCollection[_intLoop].type=='checkbox')
                {
                    if(chkCollection[_intLoop].id.indexOf('chkSend')>-1)
                    {   
                        if(chkCollection[_intLoop].checked && chkCollection[_intLoop].disabled == false)
                        {                            
                            blnChecked = true;
                        }
                    }
                }
            }

            if(blnChecked == false)
            {
                alert('<%= GetGlobalResourceObject("JSMessagesResources","JS_VAL_104") %>');
            }
            return blnChecked;
        }
        function TABLE1_onclick() {

        }

    </script>
    
    

    <div id="bd" class="clear-fix" style="clear: both;">
        <div id="content-wrap">
            <div id="tdClientSetupMenus" runat="server" align="left" valign="bottom">
                <UCClientSetupMenu:ClientSetupMenu ID="ClientSetupMenu1" runat="server" />
            </div>
            <div class="tab-page-wrap">
                <div class="page-head with-tabs">
                    <div class="inside clear-fix">
                    </div>
                </div>
                <div class="page-body">
                    <div class="mod-wrap">
                        <span class="xtop"></span>
                        <div class="mod-wrap-body">
                            <div id="dvErrorMessage" runat="server" visible="true" class="validation">
                                <asp:Label ID="lblMsg" CssClass="error-summary" runat="server" EnableViewState="false"
                                    Visible="true"></asp:Label>
                            </div>
                            <div>
                                <UCClientNameUserControl:ClientNameUserControl ID="ClientNameUserControl" runat="server" />
                            </div>                           
                            <reduc:ModuleOpener runat="server" ID="ModuleOpener1" Title="<%$ Resources:UIPagesResources, title_ADDNEWAPPRGROUP %>"
                                OpenAtStart="true" />
                            <div class="yui-g">
                                <div class="yui-u first">
                                    <fieldset class="vertical-hr-right">
                                        <div id="Div111" class="control-box" runat="server">
                                            <asp:Label ID="lblCaptionAdjustmentID" runat="server" CssClass="lblLevel2RightAlign"
                                                Text='<%# AppendRequiredField("UIPagesResources", "LBL_NAME") %>'></asp:Label>
                                            <asp:TextBox ID="txtApprovalGroupName" CssClass="txtLevel2" MaxLength="50" Width="200px"
                                                runat="server"></asp:TextBox>
                                                <div style="clear: both;">
                                                    <asp:RequiredFieldValidator ID="rfvName" runat="server" CssClass="errorTextMessage"
                                                        ControlToValidate="txtApprovalGroupName" ErrorMessage="<%$ Resources:CustomErrorsResources, ADMIN_GROUPNAME_REQ%>"
                                                        ValidationGroup="NewGroup"></asp:RequiredFieldValidator>
                                                </div>
                                            <asp:Label ID="AdminApprovalGroupLabel" runat="server" CssClass="lblLevel2RightAlign" Text="<%$ Resources:UIPagesResources, LBL_ADMIN_APPROVAL_GROUP%>"></asp:Label>
                                            <asp:CheckBox ID="AdminApprovalGroupField" CssClass="chkLevel2" runat="server" Checked="false" />
                                        </div>                                        
                                    </fieldset>
                                </div>
                                <div class="yui-u">
                                    <fieldset>
                                        <div id="Div222" class="control-box" runat="server">
                                            <asp:Label ID="Label1" runat="server" CssClass="lblLevel2RightAlign" Text="<%$ Resources:UIPagesResources, LBL_Active %>"></asp:Label>
                                            <asp:CheckBox ID="chkApprovalGroupActive" CssClass="chkLevel2" runat="server" Checked="True" />
                                        </div>                                       
                                    </fieldset>
                                </div>
                            </div>
                            <div id="inline_control">
                                <div class="form-action-controls" id="grbar" runat="server">
                                    <ul>
                                        <li id="liSave" runat="server">
                                            <asp:Button ID="Button1" runat="server" Text="<% $ Resources:ButtonsResources, BTN_ADD %>"
                                                CssClass="form-action-control" OnClick="btnAddApprovalGroup_Click" ValidationGroup="NewGroup"
                                                CausesValidation="true" />
                                        </li>
                                    </ul>
                                </div>
                            </div>
                            <reduc:ModuleCloser runat="server" ID="ModuleCloser1" />
                            <div class="module-divider">
                            </div>
                            <reduc:ModuleOpener runat="server" ID="lblExpReports" Title="<%$ Resources:UIPagesResources, TITLE_SETUPAPPROVALGROUP %>"
                                OpenAtStart="true" />
                            <div class="control-box">
                            
                                <asp:UpdatePanel ID="UpdatePanel5" runat="server">
                                    <ContentTemplate>
                                        <div class="RadGrid_zerochaos">
                                            <telerik:RadGrid ID="ZeroChaosGrid" Width="100%" DataSourceID="ListLinqDataSource"
                                                OnContextCreating="OnListDataContextCreating" AllowFilteringByColumn="true" ShowGroupPanel="false"
                                                AllowSorting="true" AllowPaging="true" runat="server" AllowMultiRowEdit="true" AutoGenerateColumns="false"
                                                PageSize="50" EnableHeaderContextMenu="true" OnItemCommand="ApprovalGroup_ItemCommand"
                                                OnItemDataBound="ApprovalGroup_ItemDataBound">
                                                <ClientSettings AllowColumnsReorder="false" AllowDragToGroup="false">
                                                    <Scrolling AllowScroll="false" UseStaticHeaders="true" SaveScrollPosition="true" />
                                                    <Resizing AllowColumnResize="true" AllowRowResize="true" EnableRealTimeResize="true"
                                                        ResizeGridOnColumnResize="false" ShowRowIndicatorColumn="false" />
                                                    <Selecting AllowRowSelect="true"></Selecting>
                                                </ClientSettings>
                                                <MasterTableView DataKeyNames="ApprovalGroupID" CommandItemSettings-ShowAddNewRecordButton="false"
                                                    CommandItemSettings-ShowRefreshButton="false" CommandItemDisplay="Top">
                                                    <PagerStyle Position="Bottom" HorizontalAlign="Left" Mode="NextPrevAndNumeric" AlwaysVisible="True"
                                                        CssClass="rgPager" />
                                                    <Columns>
                                                        <%--<telerik:GridTemplateColumn UniqueName="ApprovalGroupName" DataType="System.String" Visible="true" DataField="ApprovalGroupName"
                                                            ReadOnly="false" ItemStyle-Width="300px" HeaderStyle-Width="300px" FilterControlWidth="305"
                                                            HeaderText="<%$ Resources:UIPagesResources, HDR_GROUP_NAME %>" HeaderStyle-HorizontalAlign="Left"
                                                            ItemStyle-HorizontalAlign="Left" SortExpression="ApprovalGroupName" AllowFiltering="true"
                                                            AutoPostBackOnFilter="true" ShowFilterIcon="false" >
                                                            <ItemTemplate>
                                                                <asp:TextBox ID="ApprovalGroupNameTextBox" CssClass="txt_grid" runat="server" MaxLength="50"
                                                                    Width="300px" Text='<%# Convert.ToString(Eval("ApprovalGroupName")) %>'></asp:TextBox>
                                                                <asp:RequiredFieldValidator ID="GridApprovalNameRequiredFieldValidator" runat="server"
                                                                    ControlToValidate="ApprovalGroupNameTextBox" Display="None" ErrorMessage="<%$ Resources:CustomErrorsResources, ADMIN_GROUPNAME_REQ%>"
                                                                    Font-Size="Smaller" ValidationGroup="EditGroup"></asp:RequiredFieldValidator>
                                                            </ItemTemplate>
                                                        </telerik:GridTemplateColumn>--%>
                                                        <telerik:GridBoundColumn UniqueName="ApprovalGroupName" DataField="ApprovalGroupName"
                                                        HeaderText="<%$ Resources:UIPagesResources, HDR_GROUP_NAME %>" ReadOnly="True"
                                                        FilterControlWidth="50" SortExpression="ApprovalGroupName" AllowFiltering="true"
                                                        AutoPostBackOnFilter="true" ShowFilterIcon="false" DataType="System.String">
                                                        <HeaderStyle HorizontalAlign="Center" Width="70" />
                                                        <ItemStyle HorizontalAlign="Center" />
                                                    </telerik:GridBoundColumn>
                                                        <telerik:GridTemplateColumn AllowFiltering="false" UniqueName="IsAdminApprovalGroup"
                                                            FilterControlWidth="50" HeaderText="<%$ Resources:UIPagesResources, HDR_ADMIN_APPROVAL_GROUP %>">
                                                            <HeaderStyle HorizontalAlign="Center" Width="50px" Wrap="false" />
                                                            <ItemStyle HorizontalAlign="Center" Width="50px" />
                                                            <ItemTemplate>
                                                                <asp:CheckBox ID="AdminApprovalGroupField" runat="server" Checked='<%# Eval("IsAdminApprovalGroup")!=DBNull.Value ?Convert.ToBoolean(Eval("IsAdminApprovalGroup")):false %>'
                                                                    Enabled='<%# (!Convert.ToBoolean(Eval("IsAdminApprovalRoleAdded")))%>' />
                                                            </ItemTemplate>
                                                        </telerik:GridTemplateColumn>
                                                        <telerik:GridTemplateColumn AllowFiltering="true" UniqueName="ApprovalGroupActive"
                                                            FilterControlWidth="50" HeaderText="<%$ Resources:UIPagesResources, COM_ACTIVE %>">
                                                            <HeaderStyle HorizontalAlign="Center" Width="50px" Wrap="false" />
                                                            <ItemStyle HorizontalAlign="Center" Width="50px" />
                                                            <FilterTemplate>
                                                                <input id="AllSendMailCheckBox" type="checkbox" onclick="SetResetCheck(this.checked, 'ApprovalGroupActiveCheckBox');" />
                                                            </FilterTemplate>
                                                            <ItemTemplate>
                                                                <asp:CheckBox ID="ApprovalGroupActiveCheckBox" runat="server" Checked='<%# Eval("ApprovalGroupActive")!=DBNull.Value ?Convert.ToBoolean(Eval("ApprovalGroupActive")):false %>'
                                                                    Visible='<%# (!Convert.ToBoolean(Eval("ApprovalGroupUsed")))%>' />
                                                            </ItemTemplate>
                                                        </telerik:GridTemplateColumn>
                                                        <telerik:GridTemplateColumn AllowFiltering="false" HeaderText="<%$ Resources:UIPagesResources, COM_ACTIONS %>"
                                                            runat="server" Groupable="false" ReadOnly="true">
                                                            <ItemStyle HorizontalAlign="Left" Width="100%" VerticalAlign="Top" />
                                                            <HeaderStyle HorizontalAlign="Left" Width="100%" />
                                                            <ItemTemplate>
                                                                <a class="action-commands" href="#open-actions-flyout" rel="trigger">
                                                                    <asp:Literal ID="Literal" runat="server" Text="<%$ Resources:UIPagesResources, COM_ACTIONS %>" />
                                                                </a>
                                                                <iframe id="iframe-flyout" frameborder="0" class="iframe-flyout" style="display: none;
                                                                    filter: alpha (opacity=0); position: absolute;"></iframe>
                                                                <div class="grid-flyout right" style="display: none;">
                                                                    <div class="point">
                                                                    </div>
                                                                    <div class="top-left">
                                                                    </div>
                                                                    <div class="top-right">
                                                                    </div>
                                                                    <div class="flyout-header">
                                                                        <h4>
                                                                            <asp:Literal ID="Literal2" runat="server" Text="<%$ Resources:UIPagesResources, COM_ACTIONS%>" /></h4>
                                                                    </div>
                                                                    <div class="flyout-body">
                                                                        <div class="flyout-shadow">
                                                                        </div>
                                                                        <ul>
                                                                            <li>
                                                                                <asp:LinkButton CssClass="hiren" ID="DeleteLinkButton" runat="server" CommandName="Edit"
                                                                                    Text="<%$ Resources:UIPagesResources, LNK_ADD_EDIT_ROLE%>">
                                                                                </asp:LinkButton>
                                                                            </li>
                                                                        </ul>
                                                                    </div>
                                                                    <div class="bottom-left">
                                                                    </div>
                                                                    <div class="bottom-right">
                                                                    </div>
                                                                </div>
                                                            </ItemTemplate>
                                                        </telerik:GridTemplateColumn>
                                                    </Columns>
                                                    <RowIndicatorColumn>
                                                        <HeaderStyle Width="20px"></HeaderStyle>
                                                    </RowIndicatorColumn>
                                                    <ExpandCollapseColumn>
                                                        <HeaderStyle Width="20px"></HeaderStyle>
                                                    </ExpandCollapseColumn>
                                                </MasterTableView>
                                            </telerik:RadGrid>
                                        </div>
                                </ContentTemplate>
                                </asp:UpdatePanel>
                            </div>
                            <div id="inline_control">
                                <div class="form-action-controls" id="li1" runat="server">
                                    <ul>
                                        <li id="li12" runat="server">
                                            <asp:Button ID="btnSave" runat="server" Text="<%$ Resources:UIPagesResources, BTN_SAVE%>"
                                                OnClick="btnSave_Click" CssClass="form-action-control" />
                                        </li>
                                    </ul>
                                </div>
                            </div>
                            <reduc:ModuleCloser runat="server" ID="mcTop1" />
                            <div class="module-divider">
                            </div>
                            <div class="form-action-controls">
                                <ul>
                                    <li>
                                        <asp:Button ID="btnBack" runat="server" CssClass="form-action-control" Text="<%$ Resources:UIPagesResources, BTN_BACK%>" />
                                    </li>
                                </ul>
                            </div>
                        </div>
                        <span class="xbottom"></span>
                    </div>
                </div>
            </div>
            <div class="page-foot">
                <div class="inside">
                    <asp:PlaceHolder ID="phTabFooter" runat="server"></asp:PlaceHolder>
                </div>
            </div>
        </div>
    </div>
    <script src="<%= Application["JavaScriptPath"]%>common.js" type="text/javascript"></script>
    <script type="text/javascript">
        var needCheckBoxToggle = true;
        function toggleCheckBoxOnLoad() {
            toggleCheckBox('AllSendMailCheckBox', 'ApprovalGroupActiveCheckBox');
        }
    </script>
</asp:Content>


Code Behind:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections.Generic;
using OboutInc.OboutSuperButton;
using ZeroChaos.ZCWeb;
using DbHelper;
using ZeroChaos.ZCWeb.ZCWebControls;
using Telerik.Web.UI;
using DbHelper.Linq;
namespace ZeroChaos.ZCWeb
{
    public partial class clsApprovalGroup : BasePage
    {
        private string strConn = string.Empty;
        private SqlConnection objSqlConn = null;
        private string strMsg = string.Empty;
        public ApprovalGroup ApprovalGroup = new ApprovalGroup();
        public TextBox TextBox = new TextBox();
        public CheckBox CheckBox = new CheckBox();
        private int intClientID;
        bool blnResult;
        private int _rowFlag = 0;
        protected DbHelper.Linq.ListPageDataContext _dataContext = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                clsErrors.Clear();
                this.lblMsg.Text = "";
                this.dvErrorMessage.Visible = false;
                lblCaptionAdjustmentID.DataBind();
                strConn = Common.getConnectionString();
                Title = clsGlobalErrorMessages.GetErrorMessage(clsGlobalizationEnumerations.eResourceFiles.UIPagesResources, "TITLE_APPROVALGROUPSETUP");
                if (strConn == string.Empty)
                {
                    clsErrors.Add("IM_GEN_PG_LD");
                    return;
                }
                if (!IsPostBack)
                {
                    this.Page.DataBind();
                }
                objSqlConn = clsDbHelper.OpenSqlConnection(strConn, strUserName);
                SetFocus("ApprovalGroupNameTextBox");
                if (Session["ClientID"] != null)
                {
                    intClientID = Convert.ToInt32(Session["ClientID"]);
                    //bindgvApprovalGroup();
                }
                //if (IsPostBack && isGridBindReq(gvApprovalGroup.ID))
                   // bindgvApprovalGroup();
            }
            catch (Exception ex)
            {
                IDictionary<string, object> varValues = new Dictionary<string, object>();
                ErrorLogger.clsErrorLogger.logError(ErrorLogger.clsErrorLogger.enumErrorTypes.AppLogicError, ex.Message + "\n\n" + ex.Source
                    + "\n\n" + ex.StackTrace, 0, "Page:" + this.Page.ToString() + " Method: Page_Load.", 1,
                    System.Diagnostics.TraceEventType.Critical, varValues);
                clsErrors.Add("APG_PG_LD_FAIL");
            }
        }

        protected void ApprovalGroup_ItemCommand(object source, GridCommandEventArgs e)
        {
            try
            {
                if (e.CommandName.Equals("Edit"))
                {
                    string ApprovalGroupID = ZeroChaosGrid.MasterTableView.DataKeyValues[e.Item.ItemIndex]["ApprovalGroupID"].ToString();
                    string ApprovalGroupName = ((TextBox)e.Item.FindControl("ApprovalGroupNameTextBox")).Text;
                    Session["ApprovalGroupID"] = ApprovalGroupID;
                    Session["ApprovalGroupName"] = ApprovalGroupName;
                    Response.Redirect("ApprovalRole.aspx", false);
                }
            }
            catch (Exception ex)
            {
            }
        }

        protected void ApprovalGroup_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is Telerik.Web.UI.GridFilteringItem)
            {
                Telerik.Web.UI.GridFilteringItem filterItem = (Telerik.Web.UI.GridFilteringItem)e.Item;
                filterItem["ApprovalGroupActive"].HorizontalAlign = HorizontalAlign.Center;

            }
            if ((e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem) && e.Item.FindControl("ApprovalGroupActiveCheckBox") != null)
            {
                CheckBox tempCheckBox = e.Item.FindControl("ApprovalGroupActiveCheckBox") as CheckBox;
                CheckBox waivedCheckBox = ((CheckBox)e.Item.FindControl("ApprovalGroupActiveCheckBox"));
                waivedCheckBox.Attributes.Add("onclick", "toggleCheckBox('AllSendMailCheckBox', '" + waivedCheckBox.ClientID + "');");
            }
        }
        /// <summary>
        /// To get the Grid Reference of the Content Page
        /// </summary>
        public Telerik.Web.UI.RadGrid GetGridReference()
        {
            return this.ZeroChaosGrid;
        }

        /// <summary>
        /// Creates an instance of the LinqDataSource, but with our custom connection string instead of its internal default
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void OnListDataContextCreating(object sender, LinqDataSourceContextEventArgs e)
        {
            SetDataContext();
            e.ObjectInstance = _dataContext;
        }

        /// <summary>
        /// Creates an instance of the LinqDataSource
        /// </summary>
        protected void SetDataContext()
        {
            if (_dataContext == null)
            {
                _dataContext = new ListPageDataContext(Common.getConnectionString());
            }
        }

        protected void btnAddApprovalGroup_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtApprovalGroupName.Text != null && txtApprovalGroupName.Text != string.Empty)
                {
                    ApprovalGroup.ClientID = intClientID; //According to the user who logs in
                    ApprovalGroup.ApprovalGroupName = txtApprovalGroupName.Text;
                    ApprovalGroup.ApprovalGroupActive = chkApprovalGroupActive.Checked;
                    ApprovalGroup.IsAdminApprovalGroup = AdminApprovalGroupField.Checked;
                    blnResult = ApprovalGroup.insert(objSqlConn, ApprovalGroup.eLoadSp.INSERT);
                    if (blnResult.Equals(true))
                    {
                        clsErrors.Add("APG_INS");
                        clsGlobalErrorMessages.DisplayErrorMessages(lblMsg, "sucMsg");
                        if (lblMsg.Text != string.Empty)
                        {
                            this.dvErrorMessage.Visible = true;
                        }
                        txtApprovalGroupName.Text = "";
                        AdminApprovalGroupField.Checked = false;
                        bindgvApprovalGroup();
                        //gvApprovalGroup.DataBind();
                    }
                    else
                    {
                        clsGlobalErrorMessages.DisplayErrorMessages(lblMsg, "errMsg");
                        if (lblMsg.Text != string.Empty)
                        {
                            this.dvErrorMessage.Visible = true;
                        }

                        txtApprovalGroupName.Text = "";
                    }
                }
            }
            catch (Exception ex)
            {
                IDictionary<string, object> varValues = new Dictionary<string, object>();
                ErrorLogger.clsErrorLogger.logError(ErrorLogger.clsErrorLogger.enumErrorTypes.AppLogicError, ex.Message
                    + "\n\n" + ex.Source + "\n\n" + ex.StackTrace, 0, "Page:" + this.Page.ToString() +
                    " Method: btnAddApprovalGroup_Click.", 1, System.Diagnostics.TraceEventType.Critical, varValues);
                clsErrors.Add("APG_INS_DPL");
            }
        }

        public void bindgvApprovalGroup()
        {
            try
            {
                DataSet _dsTierGrid = new DataSet();
                ApprovalGroup.ClientID = intClientID;
                ApprovalGroup.load(objSqlConn, ApprovalGroup.eLoadSp.SELECT_BY_ClientID, ref _dsTierGrid);
                if (Common.HasRows(ref _dsTierGrid))
                {
                    //gvApprovalGroup.DataSource = _dsTierGrid.Tables[0];
                    btnSave.Visible = true;
                    li1.Visible = true;
                }
                else
                {
                    btnSave.Visible = false;
                    li1.Visible = false;
                }
            }
            catch (Exception ex)
            {
                IDictionary<string, object> varValues = new Dictionary<string, object>();
                ErrorLogger.clsErrorLogger.logError(ErrorLogger.clsErrorLogger.enumErrorTypes.AppLogicError, ex.Message + "\n\n" + ex.Source
                    + "\n\n" + ex.StackTrace, 0, "Page:" + this.Page.ToString() + " Method: bindgvApprovalGroup.", 1,
                    System.Diagnostics.TraceEventType.Critical, varValues);
                clsErrors.Add("APG_BINDGRD_FAIL");
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                foreach (GridDataItem gvDataItem in ZeroChaosGrid.Items)
                {
                    string AppGroupID = ZeroChaosGrid.MasterTableView.DataKeyValues[gvDataItem.ItemIndex]["ApprovalGroupID"].ToString();
                    if (!string.IsNullOrEmpty(AppGroupID))
                        ApprovalGroup.ApprovalGroupID = Convert.ToInt32(AppGroupID);
                    TextBox = (TextBox)gvDataItem.FindControl("ApprovalGroupNameTextBox");
                    ApprovalGroup.ApprovalGroupName = TextBox.Text;
                    CheckBox = (CheckBox)gvDataItem.FindControl("ApprovalGroupActiveCheckBox");
                    ApprovalGroup.ApprovalGroupActive = CheckBox.Checked;
                    CheckBox AdminGroupCheckBox = (CheckBox)gvDataItem.FindControl("AdminApprovalGroupField");
                    ApprovalGroup.IsAdminApprovalGroup = AdminGroupCheckBox.Checked;
                    ApprovalGroup.ClientID = intClientID;//According to the user who logs in
                    if (TextBox.Text != null && TextBox.Text != string.Empty)
                    {
                        if (!ApprovalGroup.update(objSqlConn, ApprovalGroup.eLoadSp.UPDAT_BY_GroupID))
                        {
                            _rowFlag = 1;
                            break;
                        }
                    }
                    else
                    {
                        _rowFlag = 1;
                        clsErrors.Add("ADMIN_GROUPNAME_REQ");
                        break;
                    }

                }


                if (_rowFlag == 1)
                {
                    clsGlobalErrorMessages.DisplayErrorMessages(lblMsg, "errMsg");
                    if (lblMsg.Text != string.Empty)
                    {
                        this.dvErrorMessage.Visible = true;
                    }
                }
                else
                {
                    clsErrors.Add("APG_UPDATE");
                    clsGlobalErrorMessages.DisplayErrorMessages(lblMsg, "sucMsg");
                    if (lblMsg.Text != string.Empty)
                    {
                        this.dvErrorMessage.Visible = true;
                    }
                }
                if (_rowFlag != 1)
                {
                    bindgvApprovalGroup();
                    ZeroChaosGrid.DataBind();
                }
            }
            catch (Exception ex)
            {
                IDictionary<string, object> varValues = new Dictionary<string, object>();
                ErrorLogger.clsErrorLogger.logError(ErrorLogger.clsErrorLogger.enumErrorTypes.AppLogicError, ex.Message
                    + "\n\n" + ex.Source + "\n\n" + ex.StackTrace, 0, "Page:" + this.Page.ToString() +
                    " Method: btnSave_Click.", 1, System.Diagnostics.TraceEventType.Critical, varValues);
                clsErrors.Add("APG_UPDATE_FAIL.");
            }
        }
    }
}

0
Maria Ilieva
Telerik team
answered on 04 Jul 2013, 12:07 PM
Hello,

I suppose that the error you are facing is due to the fact that  you change the data source configuration and the grid persists the indexes of the rendered items - but when the datasource is changed some of the indexes may not be valid anymore when you try to sort.

Regards,
Maria Ilieva
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Scott
Top achievements
Rank 1
answered on 24 Feb 2015, 08:30 PM
An "Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: Specified argument was out of the range of valid values.
Parameter name: ItemHierarchicalIndex" error was occurring for me.

So I switched from a <telerik:GridButtonColumn> to a <telerik:GridClientDeleteColumn> and the problem appears to have gone away.  My delete button is being created declaratively instead of programmatically however.
Tags
Grid
Asked by
Anton
Top achievements
Rank 1
Answers by
Anton
Top achievements
Rank 1
Sebastian
Telerik team
Mohamed
Top achievements
Rank 1
Maria Ilieva
Telerik team
Scott
Top achievements
Rank 1
Share this question
or