2010-07-06 47 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> 
相關問題