private void UpdateAndSaveRow(GridViewRow row, VesselValidation collection, bool save)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                string currentUser = HttpContext.Current.User.Identity.Name.ToString(),
                    key = VesselMasterGrid.DataKeys[row.RowIndex]["RowId"].ToString();
                Label lblValidated = (Label)row.FindControl("lblValidated"),
                    lblComments = (Label)row.FindControl("lblComments");
                DropDownList ddlValidated = (DropDownList)row.FindControl("ddlValidated");
                TextBox txtComments = (TextBox)row.FindControl("txtComments");
                VesselValidationRecord collectionItem = collection.Find(key);
                if (collectionItem == null) return;

                #region Adds Comments if comments are filled out

                if (txtComments.Text.Length > 0)
                {
                    collectionItem.Comments = txtComments.Text;
                    collectionItem.ChangedBy_Name = currentUser;
                }

                #endregion

                #region Adds ReviewedBy_Name & Validated if validation was changed

                if (!(collectionItem.Validated == ddlValidated.SelectedItem.Text))
                {
                    if (ddlValidated.SelectedItem.Text.Trim() == "N")
                    {
                        collectionItem.Validated = ddlValidated.SelectedItem.Text;
                        collectionItem.ReviewedBy_Name = null;
                    }
                    else
                    {
                        collectionItem.Validated = ddlValidated.SelectedItem.Text;
                        collectionItem.ReviewedBy_Name = currentUser;
                        collectionItem.ChangedBy_Name = currentUser;
                    }
                }

                #endregion

                if (save)
                    collectionItem.Save();
            }
        }
 private void  SetGridViewDirty(VesselValidation sv, bool save)
 {
     foreach (GridViewRow row in VesselMasterGrid.Rows)
     {
         if (row.RowType == DataControlRowType.DataRow)
             UpdateAndSaveRow(row, sv, save);
     }
 }