2010-07-06 46 views
0

我有一个在asp.net和c#.net应用程序中有多个页面的devexpress网格。我想在网格的所有页面中只做2个选择。如果我在所有页面中选择超过2行,它应该显示一条警告在devexpress网格的所有页面中选择的行数

如何获取在devexpress网格的所有页面中选择的行数?

回答

0

我们建议您使用以下方法:

1)通过有关从服务器端的当前选择的记录客户端使用CustomJSProperties事件的信息。 2)使用ASPxGridView的客户端Init和SelectionChanged事件来管理选择。下面是代码:

// 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> 
相关问题