How to use arrow key to go different text box in gridview
<p>I have a gridview, in that I have 3 text box in each row.
If I keypress down arrow it should go to next row textbox
If I press uparrow key then it should go previous row textbox.
same for left and right arrow key.</p>

<p>This is my code.</p>

<pre><code>&lt;script type="text/javascript" language="javascript"&gt;
    $(document).ready(function () {
        $("body").keydown(function (e) {
            var row;
            debugger;
            if (e.keyCode == 39) {
                row = $(this).closest('td').next();
                row.find('input').focus();
            }
            else if (e.keyCode == 37) {
                row = $(this).closest('td').prev();
                row.find('input').focus();
            }
            else if (e.keyCode == 40) //down arrow key code
            {
                row = $(this).closest('tr').next();
                row.closest('td').next().find('.masked').focus();
            }
            else if (e.keyCode == 38) // up arrow key code
            {
                row = $(this).closest('tr').next();
                row.closest('td').prev().find('.masked').focus();
            }
        }); //this code detect is it up or down arrow
    });

&lt;/script&gt;
</code></pre>

<p>HTML derived code</p>

<pre><code>' &lt;tr&gt;
&lt;td style="width:1%;"&gt;
&lt;td style="width:3%;"&gt;
&lt;td style="width:3%;"&gt;
&lt;td style="width:3%;"&gt;
&lt;td style="width:3%;"&gt;
&lt;td style="width:5%;"&gt;
&lt;input id="ContentPlaceHolderMain_grdDistanceLog_txttime_0" class="masked ui-mask" type="text" style="width:50px;display:block;" maxlength="8" name="ctl00$ContentPlaceHolderMain$grdDistanceLog$ctl02$txttime"&gt;
&lt;span id="ContentPlaceHolderMain_grdDistanceLog_lbltime_0" style="display:none;"&gt;&lt;/span&gt;
&lt;/td&gt;
&lt;td style="width:3%;"&gt;
&lt;td style="width:3%;"&gt;
&lt;td style="width:3%;"&gt;
&lt;td style="width:3%;"&gt;
&lt;td style="width:7%;"&gt;
&lt;td style="width:3%;"&gt;
&lt;td style="width:4%;"&gt;
&lt;/tr&gt;
&lt;tr class="alt"&gt;
&lt;td style="width:1%;"&gt;
&lt;td style="width:3%;"&gt;
&lt;td style="width:3%;"&gt;
&lt;td style="width:3%;"&gt;
&lt;td style="width:3%;"&gt;
&lt;td style="width:5%;"&gt;
&lt;input id="ContentPlaceHolderMain_grdDistanceLog_txttime_1" class="masked ui-mask" type="text" style="width:50px;display:block;" maxlength="8" name="ctl00$ContentPlaceHolderMain$grdDistanceLog$ctl03$txttime"&gt;
&lt;span id="ContentPlaceHolderMain_grdDistanceLog_lbltime_1" style="display:none;"&gt;&lt;/span&gt;
&lt;/td&gt;
&lt;td style="width:3%;"&gt;'
</code></pre>
