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

RadGrid won't work in EditMode=InPlace

4 Answers 218 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mikel
Top achievements
Rank 1
Mikel asked on 30 Jun 2011, 11:37 AM
Hello,

I am trying to build a Radgrid based on this example:
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/editondblclick/defaultcs.aspx

It works fine when I set EditMode to PopUp or  EditForms, but when I try to set it to InPlace I get the following error after a double click on a row:

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

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: index

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: index] System.Web.UI.ControlCollection.get_Item(Int32 index) +8673582 Telerik.Web.UI.GridTextBoxColumnEditor.LoadControlsFromContainer() +67 Telerik.Web.UI.GridColumnEditorBase.InitializeFromControl(Control containerControl) +50 Telerik.Web.UI.GridDataItem.InitializeEditorInCell(IGridEditableColumn column) +157 Telerik.Web.UI.GridEditManager.GetColumnEditor(IGridEditableColumn column) +175 Telerik.Web.UI.GridBoundColumn.FillValues(IDictionary newValues, GridEditableItem editableItem) +82 Telerik.Web.UI.GridEditableItem.ExtractValues(IDictionary newValues) +164 Telerik.Web.UI.GridTableView.ExtractValuesFromItem(IDictionary newValues, GridEditableItem editedItem) +116 Telerik.Web.UI.GridItemBuilder.CreateItems(GridGroupingContext group) +1117 Telerik.Web.UI.GridTableView.CreateItems(IEnumerator enumerator, GridColumn[] columns, ControlCollection controls) +187 Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource) +1573 Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +768 System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57 System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142 Telerik.Web.UI.GridTableView.PerformSelect() +38 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73 Telerik.Web.UI.GridTableView.DataBind() +354 Telerik.Web.UI.GridTableView.Rebind() +98 Telerik.Web.UI.GridCommandEventArgs.ExecuteCommand(Object source) +395 Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) +191 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +137 Telerik.Web.UI.GridItem.FireCommandEvent(String commandName, Object commandArgument) +80 Telerik.Web.UI.RadGrid.RaisePostBackEvent(String eventArgument) +4806 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 



When I debug the page after a double click I can see the DataSource is correctly set in the NeedDataSource event, all rows are properly handled in the ItemCreated and ItemDataBound events the same way they are when I use an other EditMode. But after this I get the above error only in EditMode=InPlace.

Does anyone know what could be the problem?

4 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 30 Jun 2011, 02:58 PM
Hi Mikel,

 Can you share your grid configuration / code behind? The referenced demo shows edit on double click for a grid exactly in InPlace EditMode. The error you are getting indicates that you are trying to access an index of a collection that it out range. Can you specify from which event the error is thrown (e.g. ItemCreated, ItemDataBound etc.), the stack trace for the exception will probably contain this information.

Regards,
Marin
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Mikel
Top achievements
Rank 1
answered on 30 Jun 2011, 04:24 PM
Hello Marin,

thanks for your reply, I was making a simplified version of my page to share and while doing this I found and solved the problem.  The mistake was in the ItemDataBound event.
protected void gridResult_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem && !e.Item.IsInEditMode)
    {
        //RadGrid row in view mode
        GridDataItem gridItem = (GridDataItem)e.Item;
        Hoursheet hs = (Hoursheet)e.Item.DataItem;
 
        gridItem["StartTime"].Text = hs.StartTime.ToString("HH:mm");
// etc. etc.
    }
    else if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
    {
        //RadGrid row in edit mode
        GridEditFormItem gridItem = (GridEditFormItem)e.Item;
        TextBox OID = (TextBox)gridItem["OID"].Controls[0];
        Hoursheet hs = Hoursheet.Retrieve(OID.Text);
 
        RadMaskedTextBox startTijd = (RadMaskedTextBox)gridItem["Starttijd"].Controls[0];
        startTijd.Text = hs.Starttijd.ToString("HH:mm");
// etc. etc.
    }
}

I was missing the "&& !e.Item.IsInEditMode"  condition in my if-statement, so it also tried to set these fields for the GridDataItem while in editmode, which apperently causes the error (only for inPlace editing!). 

Thanks again,
Mikel
0
Sheela
Top achievements
Rank 1
answered on 23 May 2012, 09:20 PM
Hi,
Is this problem solved .
I am getting same error . 
I am trying to load the RadGrid with all rows in edit mode with all columns blank except 1st column . 
The grid is getting loaded correct but if I do any other action on the page then it is throwing above exception .

Could you please help me ? 

My code snippet :

.aspx :

 <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="rgSKUDetails">
            <UpdatedControls>
            <telerik:AjaxUpdatedControl ControlID="rgSKUDetails" />
       <%-- <telerik:AjaxUpdatedControl ControlID="Label1" />--%>
            </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
           </telerik:RadAjaxManager>
            
            <telerik:RadGrid ID="rgSKUDetails" runat="server" AutoGenerateColumns="False" 
                GridLines="Vertical"  Skin="Web20"  
                onprerender="rgSKUDetails_PreRender" Height="444px" 
                onitemcreated="rgSKUDetails_ItemCreated" 
                onitemdatabound="rgSKUDetails_ItemDataBound" AllowPaging="True" 
                PageSize="5" >
                <PagerStyle AlwaysVisible="True" EnableSEOPaging="True" ShowPagerText="False" />
<MasterTableView AllowAutomaticInserts="True" EditMode="InPlace"  DataKeyNames= "LNo">
</MasterTableView>
                <ClientSettings  > <%-- EnablePostBackOnRowClick ="True"--%>
                    <Scrolling AllowScroll="True" UseStaticHeaders="True"  />
    <%--                 <ClientEvents OnGridCreated="GridCreated" />--%>
                   <%-- <Selecting AllowRowSelect="true" /> --%>
                </ClientSettings>
                
            </telerik:RadGrid>
            <telerik:GridTextBoxColumnEditor ID="grdtxtEditor1" runat="server">
            </telerik:GridTextBoxColumnEditor>
            <telerik:GridDateTimeColumnEditor ID="grdDateEditor1"
                runat="server">
             </telerik:GridDateTimeColumnEditor>
             <telerik:GridNumericColumnEditor ID="grdNumColEditor" runat="server">
                </telerik:GridNumericColumnEditor>
                

.cs code :
 protected void Page_Load(object sender, EventArgs e)
    {
        //rgSKUDetails.Columns.Add(); 
        if (!IsPostBack)
        {
           rgSKUDetails.PageSize = 10;
         
            BuilSKUGrid(10);
            for (int i = 0; i < rgSKUDetails.PageSize; i++)
            {
                rgSKUDetails.EditIndexes.Add(i);
            }
        }

 public void BuilSKUGrid(int RowCnt)
    {
        DataTable dt = new DataTable();
        DataRow dtRow;
        ISingleResult<web_GET_SKUColumnDetailsResult1> ColList = GetColumDetails();
       // int i = 0;
        List<web_GET_SKUColumnDetailsResult1> ResultColList = new List<web_GET_SKUColumnDetailsResult1>(ColList);
        foreach (web_GET_SKUColumnDetailsResult1 Item in ResultColList)
        {
            GridBoundColumn col = new GridBoundColumn();
            DataColumn col1 = new DataColumn(); 
            col.UniqueName = Item.ColumnName.ToString();  
            col.HeaderText = Item.ColHeader.ToString();
            //col.ColumnEditorID. = this.grdtxtEditor1;   
           // col.IsEditable = true;
           // col.ItemStyle.Width = Convert.ToInt32(Item.ColWidth);
            col.EmptyDataText = "";
            col.DataField = Item.ColumnName.ToString();
            if (Item.ColumnName == "LNo")
            {
                col.ReadOnly = true;
                col1 = new DataColumn(Item.ColumnName, typeof(int));
            }
            else
            {
                col.ReadOnly = false;
                col1 = new DataColumn(Item.ColumnName, typeof(string));
            }
           // col.IsEditable = true; 
            rgSKUDetails.Columns.Add(col);
            
         
            //Create DataTbale with empty rows
            
            dt.Columns.Add(col1);  
        }
        int colCnt = dt.Columns.Count;
        string emptyText = "";
        for (int i = 0; i < RowCnt; i++)
        {DataColumn dcol = dt.Columns["LNo"]; 
            for (int j = 0; j < colCnt; j++)
            {
                dtRow = dt.NewRow();
                dt.Rows.Add(dtRow);   
                dt.Rows[i].ItemArray[j] = emptyText.ToString();
                
            }
            int L = i+1;
            dt.Rows[i].SetField(dcol, L);
            //dt.Rows[i].ItemArray[] = (i + 1).ToString() ;  
        }
        rgSKUDetails.DataSource = dt;
        rgSKUDetails.DataBind(); 
    
    }




    protected void rgSKUDetails_PreRender(object sender, EventArgs e)
    {


        foreach (GridDataItem dataItem in rgSKUDetails.MasterTableView.Items)
        {
            if (dataItem.Selected)
            {
                dataItem.Edit = true;
            }
        }
        rgSKUDetails.Rebind();  
      
    }
    }

0
Marin
Telerik team
answered on 27 May 2012, 03:11 PM
Hi,

 Such error can happen if the grid is not databound correctly. We recommend using the Advanced Data Binding with NeedDataSource event to bind the control in this case (you do not need to call explicitly the DataBind() method when using the NeedDataSource event).

All the best,
Marin
the Telerik team
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 their blog feed now.
Tags
Grid
Asked by
Mikel
Top achievements
Rank 1
Answers by
Marin
Telerik team
Mikel
Top achievements
Rank 1
Sheela
Top achievements
Rank 1
Share this question
or