Asp.net

ASPXGridView ClientSideEvents 如何獲取選定行的 KeyField 值

  • December 18, 2014

我正在嘗試在客戶端獲取選定的網格行 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, 'MyKeyFieldName', OnGetRowValues); }">
//This gives the same result with Method #2

問題是:如何在沒有回調或回發的情況下在客戶端 RowClick 事件中收集(不是先前但)目前選定行的 KeyField 值?

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

引用自:https://stackoverflow.com/questions/8867273