tags:

views:

34

answers:

1

i have a devexpress grid with multiple pages in asp.net and c#.net application. and i want to make only 2 selection in all the pages of the grid . if i select more than 2 rows in all thepages it should display an alert

how to get the count of number of rows selected in all the pages of the devexpress grid?

A: 

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 &amp;&amp; selectedCount &gt; 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>
DevExpress Team