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

Unable to cast object of type 'Telerik.WebControls.GridCommandItem' to type 'Telerik.WebControls.GridDataItem'

1 Answer 75 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Abiri Masoni
Top achievements
Rank 1
Abiri Masoni asked on 07 Jan 2010, 09:47 AM

Hi all!

I have the following code below which throws the above error

protected

 

 

void ViewStudentGrid_ItemCommand(object source, Telerik.WebControls.GridCommandEventArgs e)

 

{

 

 

//Get the GridDataItem of the RadGrid , the row below cause the error

 

 

 

GridDataItem item = (GridDataItem) e.Item;

 

 

 

//Get the primary key value using the DataKeyValue.

 

 

 

Guid gdStudId = new Guid(item.OwnerTableView.DataKeyValues[item.ItemIndex]["StudId"].ToString());

 

 

 

try

 

{

 

 

DeleteClass.DeletePeriods(gdStudId);

 

 

 

//ParameterManager.CourseTypeDelete(CourseID);

 

}

 

 

catch (Exception ex)

 

{

ViewStudentGrid.Controls.Add(

 

new LiteralControl("Unable to Delete Record. Reason: " + ex.Message));

 

e.Canceled =

 

true;

 

}

 

 

}

 

and yet in this other code below, the casting works fine.

 

protected

 

 

void PeriodsRadGrid_DeleteCommand(object source, Telerik.WebControls.GridCommandEventArgs e)

 

{

 

 

//Get the GridDataItem of the RadGrid, no error caused in line below

 

 

 

GridDataItem item = (GridDataItem)e.Item;

 

 

 

//Get the primary key value using the DataKeyValue.

 

 

 

Guid gdPeriodId = new Guid(item.OwnerTableView.DataKeyValues[item.ItemIndex]["PeriodId"].ToString());

 

 

 

try

 

{

 

 

DeleteClass.DeletePeriods(gdPeriodId);

 

 

 

//ParameterManager.CourseTypeDelete(CourseID);

 

}

 

 

catch (Exception ex)

 

{

StudyPeriodsGrid.Controls.Add(

 

new LiteralControl("Unable to Delete Record. Reason: " + ex.Message));

 

e.Canceled =

 

true;

 

}

}

What could be the difference in the casting in both cases.

Thnx so much.

1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 08 Jan 2010, 12:26 PM
Hello Abiri,

Please find our answer to your questions in the other thread you have open on the same subject.

Sincerely yours,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
General Discussions
Asked by
Abiri Masoni
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or