Tuesday, 14 August 2012

How to create a programme for Multiple row entry in grid view like excel sheet


How to create a programme for Multiple row entry in grid view like excel sheet



How to create a programme for Multiple row entry in grid view like excel sheet



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

<!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>Untitled Page</title>

//Java Script code

    <script type="text/javascript">
    function eventclick(obj) {
   
          
    var tr = obj.parentNode.parentNode; tr.parentNode.rows[tr.rowIndex].cells[obj.parentNode.cellIndex].children[0].disabled = false;
            tr.parentNode.rows[tr.rowIndex].cells[obj.parentNode.cellIndex].children[0].focus();
            return;
                  
       
        }
        function enter(obj) {

            var tr = obj.parentNode.parentNode;
          
            if (event.keyCode == 40) // for down key
            {
                if (tr.rowIndex < tr.parentNode.rows.length - 1)
              
                    if (tr.parentNode.rows[tr.rowIndex + 1].cells[obj.parentNode.cellIndex].children[0] != null) {
                    tr.parentNode.rows[tr.rowIndex + 1].cells[obj.parentNode.cellIndex].children[0].disabled = false;
                    tr.parentNode.rows[tr.rowIndex + 1].cells[obj.parentNode.cellIndex].children[0].focus();
                    return;
                }
            }
            if (event.keyCode == 37) //for left key
            {
                if (obj.parentNode.cellIndex > 0)
                    if (tr.parentNode.rows[tr.rowIndex].cells[obj.parentNode.cellIndex - 1].children[0] != null) {
                    tr.parentNode.rows[tr.rowIndex].cells[obj.parentNode.cellIndex - 1].children[0].disabled = false;
                    tr.parentNode.rows[tr.rowIndex].cells[obj.parentNode.cellIndex - 1].children[0].focus();
                    return;
                }
            }
            if (event.keyCode == 39) //for right key
            {
                if (obj.parentNode.cellIndex < tr.cells.length - 1)
                    if (tr.parentNode.rows[tr.rowIndex].cells[obj.parentNode.cellIndex + 1].children[0] != null) {
                    tr.parentNode.rows[tr.rowIndex].cells[obj.parentNode.cellIndex + 1].children[0].disabled = false;
                    tr.parentNode.rows[tr.rowIndex].cells[obj.parentNode.cellIndex + 1].children[0].focus();
                    return;
                }

            }
            if (event.keyCode == 38) //up key
            {
                if (tr.rowIndex > 0)

                    if (tr.parentNode.rows[tr.rowIndex - 1].cells[obj.parentNode.cellIndex].children[0] != null) {
                    tr.parentNode.rows[tr.rowIndex - 1].cells[obj.parentNode.cellIndex].children[0].disabled = false;
                    tr.parentNode.rows[tr.rowIndex - 1].cells[obj.parentNode.cellIndex].children[0].focus();
                    return;
                }

            }
        }
            </script>

// Css Code
            <style type ="text/css">
           
            .cssgrid
            {
            position:absolute;
            left :400px;
          
            }
        </style>
</head>
<body>
    <form id="form1" runat="server">
    <div  class ="cssgrid ">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            Width="300px" AllowSorting="true" onsorting="GridView1_Sorting"
            GridLines="Both" ShowHeader="true" 
             >
        <Columns >
            <asp:TemplateField HeaderText="Roll" HeaderStyle-ForeColor="Black" SortExpression="Roll" >
            <ItemStyle Width ="200px" Height="30px"  />
                <ItemTemplate  >
                 
                    <asp:TextBox ID="txtroll" Text='<%# Eval("Roll") %>' onkeydown="enter(this)" Width="100%" Height ="25px" Font-Bold="true" Font-Size="15px" runat="server" BorderWidth="0px" onclientclick="Javascript:eventclick(this)" ></asp:TextBox>
                </ItemTemplate>

            <HeaderStyle ForeColor="Black"></HeaderStyle>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Name" HeaderStyle-ForeColor="Black" SortExpression="Name">
            <ItemStyle Width ="200px" Height="30px"/>
                <ItemTemplate>
              
                    <asp:TextBox ID="txtname"  Text='<%# Eval("name") %>' onkeydown="enter(this)" Width="100%" Height ="25px" runat="server" BorderWidth="0px"></asp:TextBox>
                </ItemTemplate>

                <HeaderStyle ForeColor="Black"></HeaderStyle>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Last Name" HeaderStyle-ForeColor="Black" SortExpression="Last_name">
            <ItemStyle Width ="200px" Height="30px" />
                <ItemTemplate>             
                    <asp:TextBox ID="txtlastname" Text='<%# Eval("last_name") %>'  onkeydown="enter(this)" Width="100%" Height ="25px" runat="server" BorderWidth="0px"></asp:TextBox>
                </ItemTemplate>

                <HeaderStyle ForeColor="Black"></HeaderStyle>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    </div>
    </form>
</body>
</html>


0 comments: