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

Insert records with IBindableTemplate causes error

2 Answers 19 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael Malone
Top achievements
Rank 1
Michael Malone asked on 13 May 2010, 03:44 PM
I can update just fine in a custom templated form but when I click the "Add new record" button that is generated by the RadGrid, I get an exception in my "InstantiateIn" method of "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index". I'm guessing I have to check whether the grid is performing an insert vs and update, but I'm not sure how to do this. 



public void InstantiateIn(System.Web.UI.Control container) 
            //This throws exception
            GridEditFormItem item = ((GridEditFormItem)(container.NamingContainer)); 
 

2 Answers, 1 is accepted

Sort by
0
Accepted
Pavlina
Telerik team
answered on 14 May 2010, 03:30 PM
Hello Michael,

You can try check the NamingContainer of current control whether it is in edit or insert mode.

For example:
public void InstantiateIn(Control container)   
    {   
        GridItem item = (GridItem)container.NamingContainer;   
        if (item is GridEditFormInsertItem)   
        {   
            //insert mode   
        }   
        else if (item is GridEditFormItem && item.IsInEditMode)   
        {   
            //edit mode   
        }   
    }

Give it a try and let me know about the result.

Sincerely yours,
Pavlina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Michael Malone
Top achievements
Rank 1
answered on 14 May 2010, 10:11 PM
That works great, thanks.... In the meantime I had found a solution by checking Item.ItemIndex. Is there any potential issue by doing it this way?

GridEditFormItem item = ((GridEditFormItem)(container.NamingContainer)) 
 
if (item.ItemIndex >= 0) 
   //Edit 
else 
   //Insert 
Tags
Grid
Asked by
Michael Malone
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Michael Malone
Top achievements
Rank 1
Share this question
or