Get item to delete from GridCommandEventArgs

2 posts, 1 answers
  1. Datamex
    Datamex avatar
    161 posts
    Member since:
    Jun 2012

    Posted 23 Sep 2009 Link to this post

    Hi,

    I'm trying to delete a record from the RadGrid.
    So i'm handling the ondeletecommand like this:

    protected void AppointmentsGrid_DeleteCommand( object source, GridCommandEventArgs e )  
        {  
          DALDataContext dc = new DALDataContext();  
     
          int appointmentID = (int)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["AppointmentID"];  
          dc.Appointments.DeleteOnSubmit(dc.GetAppointmentByID(appointmentID));  
          dc.SubmitChanges();  
     
          AppointmentsGrid.DataBind();  
        } 

    The code above works fine, but this is not an easy way to get the appointmentID.
    Unfortunately i can't the following code to work:

    DALDataContext dc = new DALDataContext();  
     
    vw_Appointment appointment = (vw_Appointment)e.Item.DataItem;  
     
    dc.Appointments.DeleteOnSubmit(dc.GetAppointmentByID(appointment.AppointmentID));  
    dc.SubmitChanges(); 

    Because the dataitem seems to be null all the time??
    Is there an explanation for this?
  2. Answer
    Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 26 Sep 2009 Link to this post

    Hi,

    DataItem is available only during data binding exactly in the same way as in standard MS GridView and DataGrid.

    Kind regards,
    Vlad
    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. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top