protected bool ValidateAndSave() { try { //Leave Start & End Period Selection this.GetLeavePeriod(ddlMonthFrom.SelectedValue.ToString(), ddlMonthTo.SelectedValue.ToString()); Int32 iMonthDiff = 0; iMonthDiff = (Convert.ToInt32(ddlMonthTo.SelectedValue.ToString()) - Convert.ToInt32(ddlMonthFrom.SelectedValue.ToString())); if (iMonthDiff < 0) { iMonthDiff = iMonthDiff + 12; } int i = 0; foreach (GridViewRow gRow in grLeaveList.Rows) { CheckBox chBox = new CheckBox(); chBox = (CheckBox)gRow.Cells[0].FindControl("chkSelect"); if (chBox.Checked == true) { DataTable dtLvTyCarryOverNature = objLeaveManager.GetLvTyCarryOverNature(grLeaveList.DataKeys[i].Values[0].ToString()); if ((dtLvTyCarryOverNature.Rows.Count > 0) && (iMonthDiff != 11)) { lblMsg.Text = gRow.Cells[1].Text + " can not assign for this package. Because carry over type leave can assign only for 1 year package."; return(false); } dtLvTyCarryOverNature.Rows.Clear(); dtLvTyCarryOverNature.Dispose(); } i++; } return(true); } catch (Exception ex) { lblMsg.Text = ""; throw (ex); } }