ASPXGridView ClientSideEvents如何获取所选行的KeyField值

Dor*_*Gen 14 asp.net devexpress client-side aspxgridview

我正在尝试在客户端获取选定的网格行KeyField值;

我曾经尝试过以下各种结果:

方法#1

<ClientSideEvents RowClick="function(s, e) {var key= grid.GetSelectedKeysOnPage()[0];}" />
//This gives previous selected rows value everytime
Run Code Online (Sandbox Code Playgroud)

方法#2

<ClientSideEvents RowClick="function(s, e) { grid.GetRowValues(grid.GetFocusedRowIndex(), 'MyKeyFieldName', OnGetRowValues); }" />
//This gives previous selected row and also gives an error: "A primary key field specified via the KeyFieldName property is not found in the underlying data source. Make sure.. blabla" But the MyKeyFieldName is true and i dont want to make a callback, i dont want to use this method!
Run Code Online (Sandbox Code Playgroud)

方法#3

<ClientSideEvents RowClick="function(s, e) { grid.GetRowValues(e.visibleIndex, 'MyKeyFieldName', OnGetRowValues); }">
//This gives the same result with Method #2
Run Code Online (Sandbox Code Playgroud)

问题是:如何在没有回调或回发的情况下在客户端RowClick事件中收集当前所选行的KeyField Value(而不是之前但是)?

Mik*_*ail 18

方法#2和#3

这两种方法都需要回调服务器.

确保已指定行选择操作所需的ASPxGridView.KeyFieldName属性.

如何在没有回调或回发的情况下收集所选行@客户端的KeyField值?

处理客户端ASPxClientGridView.SelectionChanged事件;

确定刚通过" e.isSelected "属性选择的行;

通过客户端ASPxClientGridView.GetRowKey方法确定行的keyValue .

将" e.visibleIndex "属性作为参数传递:

<ClientSideEvents SelectionChanged="function(s, e) {
    if (e.isSelected) {
        var key = s.GetRowKey(e.visibleIndex);
        alert('Last Key = ' + key);
    }
}" />
Run Code Online (Sandbox Code Playgroud)

  • 哎呀,对不起; 我的意思是visibleIndex将在排序等后更改,所以当你必须使用缓存的visibleIndex调用ASPxClientGridView.GetRowValues时,你的行将得到错误的行 (2认同)
  • 我已经有一段时间以某种方式忽略了这个问题,并且正如"风筝"所提到的那样,使用Mikhail解决方案是正确的,但对于排序,过滤条件是不可信的.我通过退出DevEx控件的使用找到了明显的解决方案..它们很好,但很不适合自定义.如,Grid控件没有"RowDataBound"事件.DevEx开发人员根据具体要求为其他活动提供建议,但他们的建议并不适合所有情况.RowDataBound是一个事件,而不是任何其他事件.等等.我现在改变了MVC + jQuery的路线,这是开发网络的一个辉煌世界. (2认同)