I have a Grid which has a GridClientSelectColumn in it and multirow selection enabled. Because I wanted to be able to be able to select rows by clicking anywhere on the row rather than just hitting the tiny checkbox I am using the JavaScript below for these events:
Then as part of the code behind for a button click I am doing a RadGrid1.SelectedItems to get all the highlighted/Selected rows. However if I select a few rows and then deselect some of them then RadGrid1.SelectedItems is returning the unselected rows still?
foreach
(GridDataItem selectedRow
in
RadGrid1.SelectedItems)
{
Bookings.bookingRequest bookRow =
new
Bookings.bookingRequest();
bookRow.empID = txtEmpId.Text;
bookRow.keepCurrent = radioKeepBookings.SelectedValue;
bookRow.woNo =
int
.Parse(selectedRow.GetDataKeyValue(
"woNo"
).ToString());
bookRow.seqNo = selectedRow.GetDataKeyValue(
"seqNo"
).ToString();
bookings.Add(bookRow);
}
var
originalClickedRowState =
null
;
var
clickedRow =
null
;
function
rgGrid_OnRowClick(sender, args) {
clickedRow = args.get_gridDataItem();
originalClickedRowState = args.get_gridDataItem().get_selected();
}
function
rgGrid_OnRowDeselecting(sender, args) {
if
(clickedRow !=
null
&& clickedRow != args.get_gridDataItem()) {
args.set_cancel(
true
);
}
}
function
rgGrid_OnRowSelecting(sender, args) {
if
(clickedRow == args.get_gridDataItem() && originalClickedRowState) {
args.set_cancel(
true
);
originalClickedRowState =
null
;
clickedRow =
null
;
}
}
function
rgGrid_OnRowSelected(sender, args) {
originalClickedRowState =
null
;
clickedRow =
null
;
}
<
ClientEvents
<br> OnRowClick="rgGrid_OnRowClick"<
br
> OnRowSelecting="rgGrid_OnRowSelecting"<
br
> OnRowDeselecting="rgGrid_OnRowDeselecting"<
br
> OnRowSelected="rgGrid_OnRowSelected" />