2012-01-15 27 views
14

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

問題是:我怎麼能發脾氣er KeyField在客戶端RowClick事件中沒有回調或回發的當前選定行的(不是之前但是)的值的KeyField值?

回答

17

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

謝謝你,但是這不是我期待的答案。我在問如何在Clientside RowClick事件中收集新選定行的Keyfield值?而ASPxClientGridView.GetSelectedKeysOnPage [0]正在改變,當選擇改變時,它不一樣。 – DortGen 2012-01-15 11:49:07

+1

您是否嘗試過我的解決方案?它產生了什麼結果? – Mikhail 2012-01-15 16:00:34

+0

如果您想使用Mikhail的解決方案,僅供參考;使用SelectionChanged事件的問題:用戶排序或過濾時;存儲的密鑰未更新(SelectionChanged事件未觸發) – kite 2012-09-11 16:03:07

0
function OnbtnOkClick(s, e) { 
    grid.GetRowValues(grid.GetFocusedRowIndex(), 'FieldName1;FieldName2', OnGetRowValues); 
} 

function OnGetRowValues(values) { 
    var fName1 = values[0]; 
    var fName2 = values[1]; 
    txt1.SetText(fName1); 
} 
1

如何在3個簡單的步驟。

在我的情況,我想,當用戶點擊該行即可從ASPxGridView字段(「ID」)的內容......

  1. 創建行點擊ClientSideEvent,並把「RowClick( s,e);「在函數中。
  2. 創建事件將調用的實際函數,如下所示 - 這裏是棘手的部分;不要使用GetFocusedRowIndex()來獲取索引,因爲它是FOCUSED索引。使用e.visibleIndex

    function RowClick(s, e) { 
        // Do callback to get the row data for 'ID' using current row. 
        MyAspxGridView.GetRowValues(e.visibleIndex, 'ID', OnGetRowId); 
    } 
    
  3. 創建您的回電得到您想要的字段。我得到'身份證'。

    function OnGetRowId(idValue) { 
        alert('ID: ' + idValue.toString()); 
    } 
    
+0

儘管這裏有一些延遲。你如何解決延遲問題? – IyaTaisho 2015-01-19 20:12:09

相關問題