【发布时间】:2010-07-06 07:18:18
【问题描述】:
我在 asp.net 和 c#.net 应用程序中有一个包含多个页面的 devexpress 网格。我只想在网格的所有页面中进行 2 选择。如果我在所有页面中选择超过 2 行,它应该显示警报
如何获取在 devexpress 网格的所有页面中选择的行数?
【问题讨论】:
标签: devexpress
我在 asp.net 和 c#.net 应用程序中有一个包含多个页面的 devexpress 网格。我只想在网格的所有页面中进行 2 选择。如果我在所有页面中选择超过 2 行,它应该显示警报
如何获取在 devexpress 网格的所有页面中选择的行数?
【问题讨论】:
标签: devexpress
我们建议您使用以下方法:
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 && 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>
【讨论】: