Click here to Skip to main content
16,020,381 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i want to make online attendance system for students i had a gridview in which i populate all the attendance of month i.e 'a' or 'p' in each cell but now i want to change the data of cell like if it show a then on click of grid it show p but doesnot get at that position

my code is as follows :

What I have tried:

<pre><div id="datagrid" style="overflow:scroll; height:400px; width:980px; ">
                    <asp:GridView ID="dgvrouteplanhead" runat="server"
                        AutoGenerateColumns="true"
                        Width="100%"
                        DataKeyNames="Name"
                        EmptyDataText="No record found !!"
        
                        CellPadding="4" ForeColor="#333333" OnRowDataBound="dgvrouteplanhead_RowDataBound">
                        <RowStyle BackColor="#E3EAEB" />
                        <EmptyDataRowStyle CssClass="gvEmpty" />
                        
                    <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                    <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                    <EditRowStyle BackColor="#7C6F57" />
                    <AlternatingRowStyle BackColor="White" />
                    </asp:GridView>
                    
                    </div>



back code in get all data in datatable

dsattan.Tables[0].Rows.Add(dsatt.Tables[0].Rows[0]["RegnNo"].ToString(), regesno, dsatt.Tables[0].Rows[0]["Name"].ToString(), dsatt.Tables[0].Rows[0]["a1"].ToString(), dsatt.Tables[0].Rows[0]["a2"].ToString(), dsatt.Tables[0].Rows[0]["a3"].ToString(), dsatt.Tables[0].Rows[0]["a4"].ToString(), dsatt.Tables[0].Rows[0]["a5"].ToString(), dsatt.Tables[0].Rows[0]["a6"].ToString(), dsatt.Tables[0].Rows[0]["a7"].ToString(), dsatt.Tables[0].Rows[0]["a8"].ToString(), dsatt.Tables[0].Rows[0]["a9"].ToString(), dsatt.Tables[0].Rows[0]["a10"].ToString(), dsatt.Tables[0].Rows[0]["a11"].ToString(), dsatt.Tables[0].Rows[0]["a12"].ToString(), dsatt.Tables[0].Rows[0]["a13"].ToString(), dsatt.Tables[0].Rows[0]["a14"].ToString(), dsatt.Tables[0].Rows[0]["a15"].ToString(), dsatt.Tables[0].Rows[0]["a16"].ToString(), dsatt.Tables[0].Rows[0]["a17"].ToString(), dsatt.Tables[0].Rows[0]["a18"].ToString(), dsatt.Tables[0].Rows[0]["a19"].ToString(), dsatt.Tables[0].Rows[0]["a20"].ToString(), dsatt.Tables[0].Rows[0]["a21"].ToString(), dsatt.Tables[0].Rows[0]["a22"].ToString(), dsatt.Tables[0].Rows[0]["a23"].ToString(), dsatt.Tables[0].Rows[0]["a24"].ToString(), dsatt.Tables[0].Rows[0]["a25"].ToString(), dsatt.Tables[0].Rows[0]["a26"].ToString(), dsatt.Tables[0].Rows[0]["a27"].ToString(), dsatt.Tables[0].Rows[0]["a28"].ToString(), dsatt.Tables[0].Rows[0]["a29"].ToString(), dsatt.Tables[0].Rows[0]["a30"].ToString(), dsatt.Tables[0].Rows[0]["a31"].ToString());


dgvrouteplanhead.DataSource = dsattan.Tables[0];
            dgvrouteplanhead.DataBind();
Posted
Updated 13-Mar-17 22:09pm
v2
Comments
Karthik_Mahalingam 14-Mar-17 2:51am    
Not clear.
Rahul Choudhary 14-Mar-17 3:14am    
what is not clear
Karthik_Mahalingam 14-Mar-17 3:15am    
a' or 'p' in each cell but now i want to change the data of cell like if it show a then on click of grid it show p but doesnot get at that position
Rahul Choudhary 14-Mar-17 3:43am    
see its a simple attendance system i.e if cell value is 'A' and on clicking on that cell value it automatically change its value to 'P' and again if i click on that cell of gridview it become 'A'

1 solution

refer this

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script>
        $(function () {
            var grid = document.getElementById('<%= GridView1.ClientID%>');
            $('td', grid).on('click', function () {
                var current = this.innerText.toLowerCase();
                if (current == 'a')
                    this.innerText = 'P';
                if (current == 'p')
                    this.innerText = 'A';
            });

        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:GridView ID="GridView1" runat="server"></asp:GridView>

    </form>
</body>
</html>



protected void Page_Load(object sender, EventArgs e)
      {

          if (!Page.IsPostBack) {
              DataTable dt = new DataTable();
              dt.Columns.Add("Col1");
              dt.Columns.Add("Col2");
              dt.Columns.Add("Col3");
              dt.Rows.Add("A", "A", "P");
              dt.Rows.Add("A", "P", "P");
              dt.Rows.Add("P", "A", "P");
              GridView1.DataSource = dt;
              GridView1.DataBind();
          }
      }


demo: fiddle - table version[^]
 
Share this answer
 
v2
Comments
Rahul Choudhary 14-Mar-17 4:30am    
this code is not working when i click on gridview cell the text 'A' is not changing to 'P'
Karthik_Mahalingam 14-Mar-17 4:32am    
create a new page and just copy paste this code and check, later on implement the same in your page..

check this demo : https://jsfiddle.net/karthikjsf/3qfvgxjd/
Rahul Choudhary 14-Mar-17 4:45am    
ya its working in "table" but it is not working in gridview
Karthik_Mahalingam 14-Mar-17 4:46am    
ultimately the gridview will be rendering as table in the browser
Rahul Choudhary 14-Mar-17 4:45am    
can you please do it in gridview

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