ASPxClientGridView.SelectionChanged Event
Fires when a user selects a row.
Declaration
SelectionChanged: ASPxClientEvent<ASPxClientGridViewSelectionEventHandler<ASPxClientGridView>>
Event Data
The SelectionChanged event's data class is ASPxClientGridViewSelectionEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
isAllRecordsOnPage | Gets whether all rows displayed within a page have been selected or unselected. |
isChangedOnServer | Gets whether a selection has been changed on the server. |
isSelected | Gets whether the row has been selected. |
processOnServer | Specifies whether or not to process the event on the server. Inherited from ASPxClientProcessingModeEventArgs. |
visibleIndex | Gets the visible index of the row whose selected state has been changed. |
Remarks
The ASPxGridView provides the following ways to select/deselect multiple rows:
The Select Command Column Item - a check box or radio button (ASPxGridViewBehaviorSettings.AllowSelectSingleRowOnly).
A row click (the ASPxGridViewBehaviorSettings.AllowSelectByRowClick property is set to true).
Use the event parameter’s processOnServer property to specify whether the grid finally processes the event on the server and fires the ASPxGridBase.SelectionChanged event or completely handles the ASPxClientGridView.SelectionChanged event on the client side without a round trip to the server.
The event’s isSelected parameter specifies whether the row is selected. To determine the selected row’s keyValue, use the GetRowKey(visibleIndex) method.
function OnSelectionChanged(s, e) {
if (e.isSelected) {
var key = s.GetRowKey(e.visibleIndex);
alert('Key = ' + key);
}
}
Note
- The SelectionChanged property is not in effect if cell merging is enabled.
- If the ASPxGridBehaviorSettings.ProcessSelectionChangedOnServer property is set to true, the selection changing is processed on the server side (the server-side ASPxGridBase.SelectionChanged event fires). The client-side SelectionChanged event is not raised.
- If the selection has been changed on the server, the ASPxClientGridViewSelectionEventArgs.isChangedOnServer property returns true. In this case, on the client side, you cannot determine what changes have been performed, so the ASPxClientGridViewSelectionEventArgs.isAllRecordsOnPage, ASPxClientGridViewSelectionEventArgs.isSelected, and ASPxClientGridViewSelectionEventArgs.visibleIndex properties are not in effect.
Example
In this example, the ASPxClientGridView.SelectionChanged
client-side event is handled to display selected contacts within the list box. Contact names are obtained using the ASPxClientGridView.GetSelectedFieldValues function.
The image below shows the result:
function OnGridSelectionChanged() {
grid.GetSelectedFieldValues('ContactName', OnGridSelectionComplete);
}
function OnGridSelectionComplete(values) {
selList.BeginUpdate();
selList.ClearItems();
for(var i = 0; i < values.length; i ++) {
selList.AddItem(values[i]);
}
selList.EndUpdate();
}