加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-15 23:41:28 所属栏目:asp.Net 来源:网络整理
导读:我试图在客户端获取选定的网格行KeyField值; 我曾经尝试过以下各种结果: 方法#1 ClientSideEvents RowClick="function(s,e) {var key= grid.GetSelectedKeysOnPage()[0];}" ///This gives previous selected rows value everytime 方法#2 ClientSideEvents
我试图在客户端获取选定的网格行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值,而不用回调或回发?

解决方法

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);
    }
}" />

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读