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

Get item to delete from GridCommandEventArgs

1 Answer 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Datamex
Top achievements
Rank 2
Datamex asked on 23 Sep 2009, 06:46 PM
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?

1 Answer, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 26 Sep 2009, 05:39 AM
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.
Tags
Grid
Asked by
Datamex
Top achievements
Rank 2
Answers by
Vlad
Telerik team
Share this question
or