Hi, I have a gridview with a checkbox column(using template field). As it is required to check all checkboxes in the gridview plus sometimes the rows could get a lot, like say 20 or more, it can be a hassle to keep checking using a mouse.
Then, I was told that spacebar can also check/uncheck, but only to 1 checkbox. The tab key is needed to move focus to the next checkbox. So I am looking to make the spacebar to check/uncheck, then move focus to the next checkbox without using the tab key. Thanks.
What I have tried:
function clickEnter(obj, event) {
var keyCode;
if (event.keyCode > 0) {
keyCode = event.keyCode;
}
else if (event.which > 0) {
keyCode = event.which;
}
else {
keycode = event.charCode;
}
if (keyCode == 32) {
document.getElementById(obj).focus();
return false;
}
else {
return true;
}
}
<---- Code behind ---->
for(int i = 0; i < GridView1.Rows.Count; i++){
CheckBox chk = (CheckBox)GridView1.Rows[i].Cells[4].FindControl("chkItems") as CheckBox;
CheckBox chkNext = (CheckBox)GridView1.Rows[i + 1].Cells[4].FindControl("chkItems") as CheckBox;
chk.Attributes.Add("onkeypress", "return clickEnter('" + chkNext.ClientID + "', event)");
}
I also tried to foreach gridview and the checked event for checkbox, but i did not have any form of success.