For all students who wanted a Demo of Saving Attendance in the table.
protected void Button1_Click(object sender, EventArgs e)
{
//ON THE CLICK OF SAVE ATTENDANCE BUTTON
DateTime vDt = DateTime.Now;
int vRegNo;
String vCourseCode;
String vSection;
String vAttendanceStatus = "";
for (int x = 0; x < GridView1.Rows.Count; x++)
{
vRegNo = Convert.ToInt16(GridView1.Rows[x].Cells[0].Text);
vCourseCode =
GridView1.Rows[x].Cells[1].Text;
vSection =
GridView1.Rows[x].Cells[2].Text;
DropDownList temp = (DropDownList)GridView1.Rows[x].Cells[3].FindControl("mydropdown");
if (temp.SelectedIndex == 0)
{
vAttendanceStatus = "P";
}
else if (temp.SelectedIndex == 1)
{
vAttendanceStatus = "A";
}
//Call
the method;
InsertAttendanceRecord(vDt, vRegNo,
vCourseCode, vSection, vAttendanceStatus);
Label1.Text = "Attendance Saved";
}
}
private void InsertAttendanceRecord(DateTime dt, int vRegNo,
String
vCourseCode, String vSection, String vAttendStatus)
{
SqlConnection vConn = new SqlConnection("server=localhost;
database=lovely; user id=sa; pwd=123");
vConn.Open();
String vQuery = "Insert
into StudentAttendanceRecord(EntryDate, RegNo, CourseCode, Section,
AttendanceStatus) values (@vDate, @vRegno, @vCourseCode, @vSection,
@vAttendStatus)";
SqlCommand vComm = new SqlCommand(vQuery, vConn);
vComm.Parameters.AddWithValue("@vDate",
dt);
vComm.Parameters.AddWithValue("@vRegno",
vRegNo);
vComm.Parameters.AddWithValue("@vCourseCode", vCourseCode);
vComm.Parameters.AddWithValue("@vSection",
vSection);
vComm.Parameters.AddWithValue("@vAttendStatus", vAttendStatus);
vComm.ExecuteNonQuery();
vConn.Close();
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
//FOR MARKING ALL PRESENT
for (int x = 0; x < GridView1.Rows.Count; x++)
{
DropDownList temp = (DropDownList)GridView1.Rows[x].Cells[3].FindControl("mydropdown");
temp.SelectedIndex = 0;
}
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
//FOR MARKING ALL ABSENT.
for (int x = 0; x < GridView1.Rows.Count; x++)
{
DropDownList temp = (DropDownList)GridView1.Rows[x].Cells[3].FindControl("mydropdown");
temp.SelectedIndex = 1;
}
}
Comments