protected void BtnAdd_Click(object sender, EventArgs e) { DateTime dt = DateTime.Today; //dt4 = obj.CheckOptionalAllotment(Convert.ToInt32(ddnclass.SelectedValue), Convert.ToInt32(ddnsection.SelectedValue)); //if (dt4.Rows.Count > 0) //{ // lblmsg.Text = "Data Already Exist"; // //BtnAdd.Enabled = false; //} //if (dt4.Rows.Count <= 0) //{ foreach (GridViewRow gvrow in gvdetails.Rows) { var DropDownList = gvrow.FindControl("DropDownList1") as DropDownList; var lblID = gvrow.FindControl("Label1") as Label; var checkbox = gvrow.FindControl("CheckBox1") as CheckBox; if (checkbox.Checked) { dtcheck = obj.SelectOptionalStudent(Convert.ToInt32(DropDownList.SelectedValue), Convert.ToInt32(lblID.Text)); if (dtcheck.Rows.Count > 0) { lblmsg.Text = "Data Already Exist"; } if (dtcheck.Rows.Count <= 0) { i = obj.AddOptionalSubject(Convert.ToInt32(ddnclass.SelectedValue), Convert.ToInt32(ddnsection.SelectedValue), Convert.ToInt32(DropDownList.SelectedValue), Convert.ToInt32(0), Convert.ToInt32(ddnteacher.SelectedValue), Convert.ToInt32(lblID.Text), "Yes", "Admin", 1, DateTime.Now.ToString("dd/MM/yyyy")); } } if (!checkbox.Checked) { // var lblID = gvrow.FindControl("Label1") as Label; // i = obj.AddOptionalSubject(Convert.ToInt32(ddnclass.SelectedValue), Convert.ToInt32(ddnsection.SelectedValue), Convert.ToInt32(ddnsubject.SelectedValue), Convert.ToInt32(0), Convert.ToInt32(ddnteacher.SelectedValue), Convert.ToInt32(lblID.Text), "No", "Admin", 1, DateTime.Now.ToString("dd/MM/yyyy")); } } lblmsg.Text = "Data Has Been Saved"; BindData(); dt1 = null; gvdetails.DataSource = dt1; gvdetails.DataBind(); ClearFields(); //} }