I have read throughly your code, it seems everything correct syntax wise, but i feel the problem you face because of the following reason.
1. Usually when the control inside the gridview control,we need to get that control using the findcontrol method in c# code. so i think ,in the sameway you have to do for the javascript also .
I have searced in google , and found these two link:
Karthik ElumalaiPosted Jun 24, 2016, 3:44 AM
Karthik ElumalaiPosted Jun 25, 2016, 2:55 AM
Ramya SPosted Jun 25, 2016, 2:52 AM