asp.net – ASPXGridView ClientSideEvents如何获取所选行的KeyField值

前端之家收集整理的这篇文章主要介绍了asp.net – ASPXGridView ClientSideEvents如何获取所选行的KeyField值前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图在客户端获取选定的网格行KeyField值;

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

方法#1

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

方法#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!

方法#3

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

问题是:如何在客户端RowClick事件中收集(不是以前的但是)当前所选行的KeyField值,而不用回调或回发?

@H_301_18@

解决方法

Method #2 and #3

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

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

How can i gather KeyField Value of selected row @ client without a callback or postback?

处理客户端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);
    }
}" />
@H_301_18@ @H_301_18@

猜你在找的asp.Net相关文章