4 Comments

First of all you should set the MasterTableView.DataKeyNames property of the RadGrid to the primary key columns:
<MasterTableView DataKeyNames="Id">

<telerik:RadGrid ID="customerOverviewRadGrid" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="customersDS" EnableLinqExpressions="false" runat="server" ondeletecommand="customerOverviewRadGrid_DeleteCommand" > <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle> <MasterTableView DataKeyNames="Id"> <Columns> . . . </Columns> </MasterTableView> </telerik:RadGrid>

Then in you’re DeleteCommand you can get you’re primary key value:

protected void customerOverviewRadGrid_DeleteCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
{
    int id = (int)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"];
    // run code to delete customer in the database . . . 
}

4 Replies to “How to get the primary key value in DeleteCommand event of a RadGrid

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts