473,471 Members | 4,616 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

event handling of dynamically created checkboxes in a dynamic table

1 New Member
In my project, initially, i am submitting which year,division and subject (of students) i want to access in the student database. Once i click the submit button, dynamic checkboxes are created in a dynamic table according to the query submited above. However i am facing a problem while accessing/event handling these checkboxes to update the attendance of students for the above submited subject back into the database! please help!

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.HtmlControls;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.WebControls.WebParts;
  12. using System.Xml.Linq;
  13.  
  14.  
  15. namespace iso_generator
  16. {
  17.     public partial class attendance : System.Web.UI.Page
  18.     {
  19.  
  20.         CheckBox cb1;
  21.         System.Data.OleDb.OleDbConnection con;
  22.         System.Data.OleDb.OleDbDataAdapter da;
  23.         System.Data.DataSet ds;
  24.  
  25.         static int inc = -1;
  26.         static int maxRows;
  27.  
  28.  
  29.  
  30.  
  31.        protected void Page_Load(object sender, EventArgs e)
  32.         {
  33.             con = new System.Data.OleDb.OleDbConnection();
  34.             con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\ISO\\DB\\db1.mdb";
  35.             con.Open();
  36.  
  37.  
  38.             string division = ddlDivision.Text;
  39.             string year = ddlYear.Text;
  40.             string subj = ddlSubject.Text;
  41.  
  42.             String query = "select * from student " +
  43.                 "where syear = '" + year + "' AND div ='" + division + "' order by roll";
  44.  
  45.             da = new System.Data.OleDb.OleDbDataAdapter(query, con);
  46.             ds = new DataSet();
  47.             da.Fill(ds, "student");
  48.             maxRows = ds.Tables["student"].Rows.Count;
  49.  
  50.  
  51.  
  52.  
  53.  
  54.         }
  55.  
  56.         protected void ATTENDANCE_SUBMIT_Click(object sender, EventArgs e)
  57.         {
  58.  
  59.             // Create a new HtmlTable object.
  60.             HtmlTable table1 = new HtmlTable();
  61.             table1.ID = ("YOURID");
  62.  
  63.             // Set the table's formatting-related properties.
  64.             table1.Border = 1;
  65.             table1.CellPadding = 1;
  66.             table1.CellSpacing = 1;
  67.             table1.BorderColor = "red";
  68.  
  69.             // Start adding content to the table.
  70.             HtmlTableRow row;
  71.             HtmlTableCell cell;
  72.             int i = 0;
  73.  
  74.  
  75.             for (int m = 0; m < 10; m++)
  76.             {
  77.                 // Create a new row and set its background color.
  78.                 row = new HtmlTableRow();
  79.                 row.BgColor = "lightyellow";
  80.                 for (int j = 0; j < 5; j++)
  81.                 {
  82.                     if (i < maxRows)
  83.                     {
  84.                         // Create a cell and set its text.
  85.                         DataRow dRow;
  86.                         dRow = ds.Tables["student"].Rows[i];
  87.  
  88.                         cb1 = new CheckBox();
  89.                   cb1.Checked = false;
  90.  
  91.                         cb1.ID = "" + dRow.ItemArray.GetValue(0).ToString();   //setting gr no to chechked box id//
  92.                         cb1.Text = dRow.ItemArray.GetValue(2).ToString() + " : " +
  93.                             dRow.ItemArray.GetValue(1).ToString();
  94.                         cb1.Height = 50;
  95.                         cb1.AutoPostBack = true;
  96.                         cb1.CheckedChanged += new EventHandler
  97.                                            (cb1_CheckedChanged);
  98.  
  99.                         cell = new HtmlTableCell();
  100.  
  101.                         cell.Controls.Add(cb1);
  102.                         // Add the cell to the current row.
  103.                         row.Cells.Add(cell);
  104.                         i++;
  105.                     }
  106.  
  107.                 }
  108.  
  109.                 // Add the row to the table.
  110.                 table1.Rows.Add(row);
  111.             }
  112.  
  113.             // Add the table to the page.
  114.             //this.Controls.Add(table1);
  115.  
  116.             form1.Controls.Add(table1);
  117.  
  118.  
  119.  
  120.  
  121.         }
  122.  
  123.         protected void cb1_CheckedChanged
  124.                 (object sender, EventArgs e)
  125.         {
  126.             string marks;
  127.             if (cb1.Checked)
  128.             {
  129.  
  130.                 DataRow drow = ds.Tables["student"].Rows[0];  //go  to 1st row of database//
  131.                 string variable = drow.ItemArray.GetValue(0).ToString(); //get 1st student GR_NO value in variable//
  132.  
  133.                 for (inc = 0; variable != cb1.ID; inc++)  //scan from 1st student GR_NO till the NON-CHECKED chckbox student GR_NO IN DATABASE//
  134.                 {
  135.                     drow = ds.Tables["student"].Rows[inc];
  136.                     variable = drow.ItemArray.GetValue(0).ToString();
  137.                 }
  138.  
  139.                 if (ddlSubject.Text == "SUB1")
  140.                 {
  141.                     marks = drow.ItemArray.GetValue(7).ToString();   //7TH COLUMN IN DATABASE IS SUBJECT1 COLUMN//
  142.                     marks = marks + 1;                //INCREMENT THE ATTENDANCE BY 1//
  143.                     drow[7] = marks;
  144.                 }
  145.  
  146.  
  147.             }
  148.  
  149.         }
  150. }
May 5 '13 #1
0 1178

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: DylanM | last post by:
I have some checkboxes that are generated from the results of a database search. At the moment, the checkboxes are part of a table making up a form. Users are going through the form, clicking the...
0
by: luca | last post by:
Hi all. My problem is that I can't handle events raised from child components within a composite server control when the control is created dynamically. Everything works fine if the same control...
2
by: Developer_Software | last post by:
Thanks in advance to anyone who can help :) I've got a placeholder control WITHIN A USER CONTROL that has its contents dynamically added and removed at runtime by a regular .aspx page. At...
3
by: johncee | last post by:
Greetings, I created a base class that has a datagrid. I've made it generic as possible so that any derived classes pass some info to the base constructor (including a SQL select stmt) &...
2
by: Wayne Sepega | last post by:
I have the following Code: foreach (MyClass d in myClassCollection) { curRadioBtn = new RadioButton(); curRadioBtn.Text = d.ToString(); curRadioBtn.GroupName = "Contact"; curRadioBtn.ID =...
3
by: navin | last post by:
Hi, i have posted it before but i got no help... I am developing a quiz application where the answers for the quiz vary in number, so i am creating checkbox and radio buttons depending on the ...
1
by: hipek | last post by:
Hi all, I programming in VS2005 C++ .NET 2.0. I dont' know how to create dynamic table. I think do something like that: int size=0; cin >size; char *table = new char;
4
by: reggiestyles | last post by:
Hi, I've got a question about prototype and event handling. I've got several div's (dynamic number) on a page that I want to set as active or inactive (basically, I'm using scriptaculous'...
9
by: dli07 | last post by:
Hello, I'm trying to convert a piece of code that creates a dynamic vertical resizing bar in a table from internet explorer to firefox. It's based on a post from...
2
by: miksy99 | last post by:
hi all, i hav created a dynamic table in javascript with no. of rows and col. being entered by the user. i hav given a mouseover event on each cell as red color and mouseout event as yellow color,...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.