Sunday, 24 June 2012

in pressing the Enter key how the user go to Next Contol using JQuery.

Source Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridviewKeydown.aspx.cs" Inherits="GridviewKeydown" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
<%--    <!-- required -->
<script type="text/javascript" src="js/jquery.js"></script>
<!-- optional -->
<script type="text/javascript" src="js/jquery.shadow.js"></script>
<script type="text/javascript" src="js/jquery.ifixpng.js"></script>
<script type="text/javascript" src="js/jquery.fancyzoom.min.js"></script>--%>

  <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
     <script language="javascript" type="text/javascript">
         $(document).ready(function ()
          {
              $(':input').bind("keydown", function (e)
             {
                 var n = $(":input").length;
                 if (e.keyCode == 13)
                 {
                     e.preventDefault();
                     var nextIndex = $(':input').index(this) + 1;
                     if (nextIndex < n)
                         $(':input')[nextIndex].focus();
                 }
             });
         });
     </script>
                                                              OR
<%--
         <script type="text/javascript"
        src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js">
    </script>
  
    <script type="text/javascript">
        $(function () {
            $('input:text:first').focus();
            var $inp = $('input:text');
            $inp.bind('keydown', function (e) {
                //var key = (e.keyCode ? e.keyCode : e.charCode);
                var key = e.which;
                if (key == 13) {
                    e.preventDefault();
                    var nxtIdx = $inp.index(this) + 1;
                    $(":input:text:eq(" + nxtIdx + ")").focus();
                }
            });
        });
    </script>--%>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:gridview ID="Gridview1" runat="server" AutoGenerateColumns="False">
    <Columns>
    <asp:TemplateField>
    <ItemTemplate>
         <asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("LedgerID")%>'></asp:TextBox>
    </ItemTemplate>
    </asp:TemplateField>

    <asp:TemplateField>
    <ItemTemplate>
         <asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("LedgerName")%>'></asp:TextBox>
    </ItemTemplate>
    </asp:TemplateField>

    <asp:TemplateField>
    <ItemTemplate>
        <asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("CompanyID")%>'></asp:TextBox>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:gridview>
    </div>
    </form>
</body>
</html>

Page Design
 
C# Code 
 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;


public partial class GridviewKeydown : System.Web.UI.Page
{
    SqlConnection con;
    SqlCommand cmd;
    DataTable dt;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetData();
        }
    }
    public void GetData()
    {
        cone();
        SqlDataAdapter da = new SqlDataAdapter("Select * from Rakesh", con);
        dt = new DataTable();
        da.Fill(dt);
        Gridview1.DataSource = dt;
        Gridview1.DataBind();
    }
    public void cone()
    {
        con = new SqlConnection(ConfigurationManager.ConnectionStrings["Satya"].ToString());
        con.Open();
    }
}

No comments:

Post a Comment