I am trying to assign the Enter key to a button inside of a gridview. Does anyone know how this can be accomplished? Thank you.
You can give the button an id on one of the rendering events of the GridView, and then with jQuery bind the keypress() to a main div that wraps your site, and have it simulate the click() event on the button in your gridview when the 'enter' key (keyCode 13) was detected.
Like this :
$(document).ready(function() {
$('#mainDivWrapperId').keypress(function(event) {
if (event.keyCode == '13') {
$('#buttonId').click();
}
});
});
Edited Addition : If you have a button in a gridview, then you just need to catch the 'enter' key press event like I've shown above, and then you can have it trigger the 'click' event of your button.
Like this :
$(document).ready(function() {
$('#mainDivWrapperId').keypress(function(event) {
if (event.keyCode == '13') {
$('#buttonId').trigger('click');
}
});
});
actually to make it simple, 1st declare the button on click event handler. 2nd declare a on keydown/keypress event handler for grid view. inside the gridview's keypress/keydown event handler, check for keycode 13 from the event argument. if the event.keycode==13, do button.click(). what ever logic inside the button's click event handler will be processed.