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

ierror n ItemDataBound: Unable to cast object of type 'Telerik.WebControls.GridInsertionObject' to type

1 Answer 299 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Neal
Top achievements
Rank 1
Neal asked on 16 Oct 2008, 02:32 PM
Hi,

While trying to Insert a row to my grid...(after a successful load and the same code already executed)
In my grids ItemDataBound event, I get the following error:
Unable to cast object of type 'Telerik.WebControls.GridInsertionObject' to type

I use the underlying datasource to retrieve the value for a checkbox and set it T or F.

The code in it
Whilst doing the following...

 

if (e.Item is GridDataItem && e.Item is GridEditableItem)

 

{

 

GridDataItem item = e.Item as GridDataItem;

 

 

CheckBox box = (CheckBox)item.FindControl("chkLstAdd");

 

Planning.

Task dataSourceRow = (Planning.Task)e.Item.DataItem;

 

 

//set custom attributes (i.e the checkbox.checked value) from the datasource:

 

box.Checked =

false;

 

 

if (dataSourceRow.IsTaskAllocated.ToString() == "True")

 

{

box.Checked =

true;

 

}

}

Should I not try prevent the "To be inserted row " from executing this code, ?  if so How?

ManyThanks
Neal

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 17 Oct 2008, 05:42 AM
Hi Neal,

Try the above given code in the ItemDataBound event as shown below.

CS:
  protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
       //to access the item in edit mode(and not in Insert mode) 
        if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode)&&!(e.Item.OwnerTableView.IsItemInserted)) 
        { 
            GridEditableItem edititem = (GridEditableItem)e.Item; 
            CheckBox box = (CheckBox)edititem.FindControl("chkLstAdd"); 
            //.... 
        } 
  } 


Thanks
Shinu.
Tags
Grid
Asked by
Neal
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or