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

2 posts, 0 answers
  1. Abiri Masoni
    Abiri Masoni avatar
    30 posts
    Member since:
    Dec 2009

    Posted 07 Jan 2010 Link to this post

    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.

  2. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 08 Jan 2010 Link to this post

    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.
  3. DevCraft banner
Back to Top