Click here to Skip to main content
15,790,022 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have used to grid control and textbox control under ItemTemplate field to my program. So, How to set the text box Navigation using Arrow(up/down) keys using 2008

1 solution

Here is the Sample Code -

<script language="javascript" type="text/javascript">
    function keyPressed(TB, e) {
        var rowscount = document.getElementById('<%=GridView1.ClientID%>').rows.length;
        if (e.keyCode == 40 || e.keyCode == 13) {
            if (TB.split("TextBox1_")[1] < (rowscount-2))
                document.getElementById(TB.split("TextBox1_")[0] + 'TextBox1_' + eval(TB.split("TextBox1_")[1] + '+1')).focus();

        if (e.keyCode == 38) {
            if (TB.split("TextBox1_")[1] >= 1)
                document.getElementById(TB.split("TextBox1_")[0] + 'TextBox1_' + eval(TB.split("TextBox1_")[1] + '-1')).focus();

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
        AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="AccessTypeID"
            <asp:TemplateField HeaderText="type" SortExpression="type">
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("type") %>'  onkeyup="keyPressed(,event)"></asp:TextBox>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:omfConnectionString %>"
        SelectCommand="SELECT * FROM [tblAccessType] WHERE ([type] LIKE '%' + @type + '%')">
            <asp:Parameter DefaultValue="work phone" Name="type" Type="String" />
Share this answer
Member 10867757 20-Jun-14 4:56am    
what is the code of aspx.cs page

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900