I'm trying to get selected grid rows KeyField value on client side;
I used to try followings and get various results:
<ClientSideEvents RowClick="function(s, e) {var key= grid.GetSelectedKeysOnPage()[0];}" />
//This gives previous selected rows value everytime
<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!
<ClientSideEvents RowClick="function(s, e) { grid.GetRowValues(e.visibleIndex, 'MyKeyFieldName', OnGetRowValues); }">
//This gives the same result with Method #2
The question is: How can i gather KeyField Value of (not previous but) current selected row at client RowClick event without a callback or postback?
Method #2 and #3
Both these methods require a callback to the server.
Make sure that you have specified the ASPxGridView.KeyFieldName property that is required for the row selection operation.
How can i gather KeyField Value of selected row @ client without a callback or postback?
Handle the client-side ASPxClientGridView.SelectionChanged event;
Determine a row that just has been selected via the “e.isSelected” property;
Determine the row’s keyValue via the client-side ASPxClientGridView.GetRowKey method.
Pass the “e.visibleIndex” property as a parameter:
<ClientSideEvents SelectionChanged="function(s, e) {
if (e.isSelected) {
var key = s.GetRowKey(e.visibleIndex);
alert('Last Key = ' + key);
}
}" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With