开发者

count of number of rows selected in all the pages of the devexpress grid

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 shoul开发者_运维问答d display an alert

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


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜