protected void BtnAdd_Click(object sender, EventArgs e) { foreach (GridViewRow gvrow in gvdetails.Rows) { var checkbox = gvrow.FindControl("CheckBox1") as CheckBox; if (checkbox.Checked) { var lblID = gvrow.FindControl("Label1") as Label; i = obj.AddClassPromotion(Convert.ToInt32(lblID.Text), Convert.ToInt32(ddnpclass.SelectedValue), Convert.ToInt32(ddnpsection.SelectedValue), "Promoted", "Teacher", Convert.ToInt32(Session["tuid"]), DateTime.Now.ToString()); j = obj.UpdateClassAllottment(Convert.ToInt32(lblID.Text), Convert.ToInt32(ddnpclass.SelectedValue), Convert.ToInt32(ddnpsection.SelectedValue)); } if (!checkbox.Checked) { var lblID = gvrow.FindControl("Label1") as Label; i = obj.AddClassPromotion(Convert.ToInt32(lblID.Text), Convert.ToInt32(ddnpclass.SelectedValue), Convert.ToInt32(ddnpsection.SelectedValue), "Not Promoted", "Teacher", Convert.ToInt32(Session["tuid"]), DateTime.Now.ToString()); } dt1 = obj.GetStudent(Convert.ToInt32(ddnclass.SelectedValue), Convert.ToInt32(ddnsection.SelectedValue)); if (dt1.Rows.Count > 0) { gvdetails.DataSource = dt1; gvdetails.DataBind(); } } BindData(); }