It looks like the only change you'll have to make is on this line:
var grid = sender as DataGrid;
You're not dealing with a DataGrid
anymore, so that line will return null
.
Just cast it to the correct element:
var grid = sender as RadGridView;