December 24, 2008
Telerik's grid control is fairly flexible, but at times can be a royal pain to use. Things that should be dirt simple are often ridiculously convoluted and impossible to figure out without wasting time digging through their documentation or visiting their support forums.
Here is how Telerik suggests getting the primary key for the first selected item in a RadGrid:
I guess something like:
would have been too obvious. Anyway, here is a helper routine I wrote to hand back an ArrayList containing the selected keys:
public ArrayList GetTelerikGridSelections(Telerik.Web.UI.RadGrid grid)
ArrayList selectedItems = new ArrayList();
if (grid.MasterTableView.DataKeyNames.Length > 0)
string key = grid.MasterTableView.DataKeyNames;
for (int i = 0; i < grid.SelectedItems.Count; i++)
I used an ArrayList rather than a strongly-typed collection to make it more flexible, but if you always use the same data type for your keys, you could change this to save yourself some effort. Note: this only looks at the MasterTableView. If you are using multiple table views in your grid you should also tweak this to receive a GridTableView instead of a RadGrid.