Tuesday, April 10, 2012

Serverside RowClick event handling for RadGrid

Here are a few steps to handle an event on the server side for Telerik's RadGrid

1. Add attribute OnItemCommand to <Telerik:RadGrid>, for example "OnItemCommand="radGrid1_ItemCommand" if your grid name is radGrad1
2. Add attribute EnablePostBackOnRowClick="true" to <ClientSettings>
3. To your code behind, add the following, which will assign a specific cell value to a string:

protected void radGrid1_ItemCommand
    // this block will take the value of the column "ContactName" from the grid and assign it to a string
    if (e.CommandName == "RowClick")
        int index = e.Item.ItemIndex;
        GridDataItem item = (GridDataItem)radGrid1.Items[index];
        string contactName = item["ContactName"].Text;

1 comment: