0
votes

I have 4 tables that I've created using RadGrid. Each of them contains a list of items I have a title of and the id of. I want to have a column with a "Remove" link that will fire an event handler in which I will write code to remove this id from the db.

Each of those tables has a separate table in the db so I need to know what table did fire the handler and what id does it correspond.

Another small question is, what should I include so that visual studio recognize GridCommandEventArgs as a type?

1

1 Answers

3
votes

You question is a little bit confusing. You can use the DeleteCommand to get the id of the row and delete it.

<telerik:RadGrid ID="RadGrid1" runat="server"
   OnDeleteCommand="RadGrid1_DeleteCommand" 
   OnNeedDataSource="RadGrid1_NeedDataSource">
   <MasterTableView DataKeyNames="Id" CommandItemDisplay="Top">
      <Columns>
         <telerik:GridButtonColumn ButtonType="ImageButton" 
            ConfirmText="Are you sure you want to delete?"
            CommandName="Delete" ImageUrl="~/Images/Delete.png" 
            Text="Click to delete" UniqueName="Delete">
         </telerik:GridButtonColumn>               
      </Columns>
   </MasterTableView>            
</telerik:RadGrid>

protected void RadGrid1_DeleteCommand(object source, GridCommandEventArgs e)
{
   int id = Convert.ToInt32(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["id"]);

   // Do delete based on the given id
}