string DetermineSelection(DataGridItem item, ref int count, string selectedItems) { CheckBox selection = (CheckBox)item.FindControlRecursive("SelectCheckBox"); if (selection != null) { if (selection.Checked) { string s = this.MyDataGrid.DataKeys[item.ItemIndex].ToString(); selectedItems += ", " + s + " "; count++; } } if (selectedItems != "") { return(selectedItems.Substring(1)); } else { return(selectedItems); } }