Hi,
We suggest that you use the following approach:
1) pass the information about the currently selected records from the server side to client side using the CustomJSProperties event.
2) use the ASPxGridView's client side Init and SelectionChanged events to manage the selection. Here is the code:
// CS
protected void grid_CustomJSProperties(object sender, ASPxGridViewClientJSPropertiesEventArgs e) {
e.Properties["cpSelectionCount"] = (sender as ASPxGridView).Selection.Count.ToString();
}
// JS
<script type="text/javascript">
var selectedCount = 0;
</script>
....
<dx:ASPxGridView ID="grid" runat="server" AutoGenerateColumns="False" KeyFieldName="CategoryID" OnCustomJSProperties="grid_CustomJSProperties" DataSourceID="AccessDataSource1">
<ClientSideEvents SelectionChanged="function(s,e) {
if(e.isChangedOnServer)
return;
if(e.isSelected)
selectedCount += 1;
else
selectedCount -= 1;
if(e.isSelected && selectedCount > 2) {
alert('You selected more than 2 records');
s.UnselectRowOnPage(e.visibleIndex);
return;
}
}"
Init="function(s,e) {
selectedCount = parseInt(s.cpSelectionCount);
}"/>
<Columns>
...
</Columns>
</dx:ASPxGridView>