I want to Edit My record,actually the last column of my grid view,I am adding attendence by placing tick mark on check box.(Tick mark Saves "Present" while uncheck saves "Absent" in the database).Now I want To Update my attendence record. I am applying my code but it is giving error.
protected void gvemployeeattendenceshow_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["Final Year Project"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "UPDATE EmployeeAttendence Set AttendenceStatus=@AttendenceStatus Where EmployeeAttendanceID=@EmployeeAttendanceID";
cmd.Connection = con;
con.Open();
foreach (GridViewRow row in gvemployeeattendenceshow.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
int EmployeeAttendanceID = int.Parse(((Label)(gvemployeeattendenceshow.Rows[e.RowIndex].Cells[1].FindControl("lblAttendenceID"))).Text);
CheckBox chkAttendence = row.FindControl("lblstatus") as CheckBox;
if(chkAttendence.Checked)
{
//Get the checked value of the CheckBox.
// string AttendenceStatus = ((CheckBox)(gvemployeeattendenceshow.Rows[e.RowIndex].Cells[1].FindControl("lblstatus"))).ToString();
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@EmployeeAttendanceID", EmployeeAttendanceID);
cmd.Parameters.AddWithValue("@AttendenceStatus", "Present");
cmd.ExecuteNonQuery();
gvemployeeattendenceshow.EditIndex = -1;
FillGrid();
}
else
{
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@EmployeeAttendanceID", EmployeeAttendanceID);
cmd.Parameters.AddWithValue("@AttendenceStatus", "Absent");
cmd.ExecuteNonQuery();
gvemployeeattendenceshow.EditIndex = -1;
FillGrid();
}
}
}
con.Close();
}
}
}
I Reached at this point. For further proceddings or for Update my attendence record I want help.!