Hi,
first of all, it is not an answer but a suggestion, can you refactor your code so that is readable?
for example:
CheckBox cBox = (CheckBox)final.Rows[i].Cells[3].FindControl("CheckBox1");
if (cBox != null)
{
RadioButtonList rButton = (RadioButtonList)final.Rows[i].Cells[2].FindControl("RadioButtonList1");
if (rButton.SelectedValue == "Half")
{
UpdateDataTable(0.5, "Approved", dtable, nam, type, rn, conn);
}
else
{
UpdateDataTable(1.0, "Approved", dtable, nam, type, rn, conn);
}
}
else
{
UpdateDataTable(0.0, "Disapproved", dtable, nam, type, rn, conn);
}
private void UpdateDataTable(float hf, string status, DataTable dTable, string nam, string type, string rn, SqlConnection conn)
{
DataRow dd = dtable.NewRow();
dd["date"] = Convert.ToDateTime(final.Rows[i].Cells[1].Text);
dd["hf"] = hf;
dd["status"] = "Approved";
dtable.Rows.Add(dd);
GridView1.DataSource = dTable;
GridView1.DataBind();
SqlCommand cmd = new SqlCommand("insert into leave_rec VALUES('" + nam + "','" + dd["date"] + "','" + dd["hf"] + "','" + type + "','" + status + "')", conn);
cmd.ExecuteNonQuery();
calculate_half(type, nam);
Session["dt"] = dTable;
}
Second, There are few things that I noticed, where you are parsing the wrong type on rButton check:
dd["date"] = final.Rows[i].Cells[1].Text;
dd["hf"] = "1";
you have defined them as DateTime and float, but assigning them string.
Finally, this is where you are having the problem I guess, lines like this,
CheckBox cBox = (CheckBox)final.Rows[i].Cells[3].FindControl("CheckBox1");
RadioButtonList rButton =(RadioButtonList)final.Rows[i].Cells[2].FindControl("RadioButtonList1");
How many controls a cell in a specific row can have in your application
If the cell can have only one control why don't you take that cell as the control, why are you searching for it?
i.e.
CheckBox cBox = (CheckBox)final.Rows[i].Cells[3];
or if you know there is a check box control named "CheckBox1" then look for that control.
i.e.
if (CheckBox1.checked)
I am not sure I answered your question, reducing unnecessary code will help you find the problem faster.
Regards
Jegan