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

RadGrid Item Delete exception Object must Implemet IConvertible

2 Answers 97 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sintayehu
Top achievements
Rank 1
Sintayehu asked on 23 Sep 2008, 10:24 PM



Hi there,

On a radGrid, I am getting an exception message that says Object must implement IConvertible! In(UserAccountGrid_ItemDeleted)When I try and delete an Item.

My rad grid has objectdatasource, It allows automaticdeletes but no autogenerated delete method rather I have my delete button made in a column.

I see this problem only when I add ID as my DataKeyName (DataKeyNames="ID,UName,DName") on the MasterTableView, My delete method works perfectly without the ID , Unfortunately I need ID for Other methods like “Replacing” an Item...

Now In my delete method I actually don’t need the ID. however It appears that If I have certain fields as datakeynames, my objectdatasource method has to implement those fields. for example If I had ColumnID as

my dataKeyName, My update delete, insert , select methods need to accept it as their parameter. It actually throws an exception saying so if they don't.

So I ended up just implementing it (faking it).

So my question is, IS this a known telerik issue?

Is there a different way to get the ID without making it my datakeyName?

2 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 24 Sep 2008, 07:21 AM
Hi luay,

Possible solution is to get the ID directly from the cell Text property. Here is an example:

string ID = ((GridDataItem)e.Item)["ID"].Text; // in case of command event

or

directly for desired item:

string ID = UserAccountGrid.Items[0]["ID"].Text; // for the first item

Sincerely yours,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Sintayehu
Top achievements
Rank 1
answered on 24 Sep 2008, 01:47 PM

I did what you recomended and removed the ID from the datakeya name and get the ID the suggested way , This doesn't work on itemCreated event but works well up on firing one of the commands like below.

Thanx!

protected void RadGridServers_DeleteCommand(object source, GridCommandEventArgs e)

{

string IDOne = ((GridDataItem)e.Item)["ID"].Text;

string IDTwo = RadGridServers.Items[0]["ID"].Text;

}

Tags
Grid
Asked by
Sintayehu
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Sintayehu
Top achievements
Rank 1
Share this question
or