Click here to Skip to main content
15,894,106 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 asp.net 2008
Posted

1 solution

Here is the Sample Code -

XML
<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();
        }
    }
</script>

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
        AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="AccessTypeID"
        DataSourceID="SqlDataSource1">
        <Columns>
            <asp:TemplateField HeaderText="type" SortExpression="type">
                <ItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("type") %>'  onkeyup="keyPressed(this.id,event)"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:omfConnectionString %>"
        SelectCommand="SELECT * FROM [tblAccessType] WHERE ([type] LIKE '%' + @type + '%')">
        <SelectParameters>
            <asp:Parameter DefaultValue="work phone" Name="type" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
 
Share this answer
 
Comments
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