在我的项目中,最初,我提交了我想在学生数据库中访问的(学生)的年份、部门和科目。单击提交按钮后,将根据上面提交的查询创建动态复选框。但是,在处理这些复选框以更新上述提交主题的学生出勤率时,我遇到了一个问题!请帮忙!代码:
使用系统;使用 System.Collections;使用 System.Configuration;使用 System.Data;使用 System.Linq;使用 System.Web;使用 System.Web.Security;使用 System.Web.UI;使用 System.Web.UI.HtmlControls;使用 System.Web.UI.WebControls;使用 System.Web.UI.WebControls.WebParts;使用 System.Xml.Linq;
namespace iso_generator
{
public partial class attendance : System.Web.UI.Page
{
CheckBox cb1;
System.Data.OleDb.OleDbConnection con;
System.Data.OleDb.OleDbDataAdapter da;
System.Data.DataSet ds;
static int inc = -1;
static int maxRows;
// static int maxRows1;
protected void Page_Load(object sender, EventArgs e)
{
con = new System.Data.OleDb.OleDbConnection();
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\ISO\\DB\\db1.mdb";
con.Open();
string division = ddlDivision.Text;
string year = ddlYear.Text;
string subj = ddlSubject.Text;
String query = "select * from student " +
"where syear = '" + year + "' AND div ='" + division + "' order by roll";
da = new System.Data.OleDb.OleDbDataAdapter(query, con);
ds = new DataSet();
da.Fill(ds, "student");
maxRows = ds.Tables["student"].Rows.Count;
}
protected void ATTENDANCE_SUBMIT_Click(object sender, EventArgs e)
{
// Create a new HtmlTable object.
HtmlTable table1 = new HtmlTable();
table1.ID = ("YOURID");
// Set the table's formatting-related properties.
table1.Border = 1;
table1.CellPadding = 1;
table1.CellSpacing = 1;
table1.BorderColor = "red";
// Start adding content to the table.
HtmlTableRow row;
HtmlTableCell cell;
int i = 0;
for (int m = 0; m < 10; m++)
{
// Create a new row and set its background color.
row = new HtmlTableRow();
row.BgColor = "lightyellow";
for (int j = 0; j < 5; j++)
{
if (i < maxRows)
{
// Create a cell and set its text.
DataRow dRow;
dRow = ds.Tables["student"].Rows[i];
cb1 = new CheckBox();
cb1.Checked = false;
cb1.ID = "" + dRow.ItemArray.GetValue(0).ToString(); //setting gr no to chechked box id//
cb1.Text = dRow.ItemArray.GetValue(2).ToString() + " : " +
dRow.ItemArray.GetValue(1).ToString();
cb1.Height = 50;
cb1.AutoPostBack = true;
cb1.CheckedChanged += new EventHandler
(cb1_CheckedChanged);
cell = new HtmlTableCell();
cell.Controls.Add(cb1);
// Add the cell to the current row.
row.Cells.Add(cell);
i++;
}
}
// Add the row to the table.
table1.Rows.Add(row);
}
// Add the table to the page.
//this.Controls.Add(table1);
form1.Controls.Add(table1);
}
protected void cb1_CheckedChanged
(object sender, EventArgs e)
{
string marks;
if (cb1.Checked)
{
DataRow drow = ds.Tables["student"].Rows[0]; //go to 1st row of database//
string variable = drow.ItemArray.GetValue(0).ToString(); //get 1st student GR_NO value in variable//
for (inc = 0; variable != cb1.ID; inc++) //scan from 1st student GR_NO till the NON-CHECKED chckbox student GR_NO IN DATABASE//
{
drow = ds.Tables["student"].Rows[inc];
variable = drow.ItemArray.GetValue(0).ToString();
}
if (ddlSubject.Text == "SUB1")
{
marks = drow.ItemArray.GetValue(7).ToString(); //7TH COLUMN IN DATABASE IS SUBJECT1 COLUMN//
marks = marks + 1; //INCREMENT THE ATTENDANCE BY 1//
drow[7] = marks;
}
}
}
}