protected void gvUsers_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                GridView gv = (GridView)sender;
                GridViewRow gvr = (GridViewRow)gv.Rows[e.RowIndex];
                Label lblSystemUserID = (Label)gvr.FindControl("lblSystemUserIDEdit");
                int id = Convert.ToInt32(lblSystemUserID.Text);
                int userRoleID = Convert.ToInt32(((DropDownList)gvr.FindControl("ddlUserRoleEdit")).SelectedValue);
                Boolean invMgmt = Convert.ToBoolean(((CheckBox)gvr.FindControl("cbInventoryManagementEdit")).Checked);

                using (FormContext ctx = new FormContext())
                {
                    var systemUser = ctx.SystemUsers.Where(su => su.SystemUserID == id).FirstOrDefault();

                    systemUser.DisplayName = ((TextBox)gvr.FindControl("txtDisplayNameEdit")).Text;
                    systemUser.EmailAddress = ((TextBox)gvr.FindControl("txtEmailAddressEdit")).Text;
                    systemUser.Status = Convert.ToInt16(((RadioButtonList)gvr.FindControl("rblUserStatusEdit")).SelectedValue);
                    systemUser.UserRole = ctx.UserRoles.Where(ur => ur.UserRoleId == userRoleID).FirstOrDefault();
                    systemUser.InventoryApprovalUser = invMgmt;

                    ctx.SystemUsers.Attach(systemUser);
                    ctx.Entry(systemUser).State = EntityState.Modified;

                    ctx.SaveChanges();
                    gvUsers.DataBind();
                    lblUserMessage.Text = "";
                }
            }
            catch (Exception ex)
            {
                lblUserMessage.Text = "Unable to update user.  Please contact your system administrator.";
            }
        }
        protected void gvSkus_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            Label lblAddSkuMessage = (Label)fvReport.FindControl("lblAddSkuMessage");

            try
            {
                GridView gv = (GridView)sender;
                GridViewRow gvr = (GridViewRow)gv.Rows[e.RowIndex];
                Label lblRecordIdEdit = (Label)gvr.FindControl("lblRecordIdEdit");
                int id = Convert.ToInt32(lblRecordIdEdit.Text);

                using (FormContext ctx = new FormContext())
                {
                    var sku = ctx.SkuQuantityItems.FirstOrDefault(x => x.RecordId == id);

                    sku.Completed = ((CheckBox)gvr.FindControl("cbCompletedEdit")).Checked;
                    sku.MaterialSku = ((TextBox)gvr.FindControl("txtMaterialSkuEdit")).Text;
                    sku.Quantity = ((TextBox)gvr.FindControl("txtQuantityEdit")).Text;

                    ctx.SkuQuantityItems.Attach(sku);
                    ctx.Entry(sku).State = EntityState.Modified;

                    ctx.SaveChanges();
                    gv.DataBind();
                    lblAddSkuMessage.Text = "";
                }
            }
            catch (Exception ex)
            {
                lblAddSkuMessage.Text = "Unable to update Material SKU# and/or Quantity.  Please contact your system administrator.";
            }
        }
        protected void gvEmailList_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                GridView gv = (GridView)sender;
                GridViewRow gvr = (GridViewRow)gv.Rows[e.RowIndex];
                Label lblEmailAddressID = (Label)gvr.FindControl("lblEmailAddressIDEdit");
                int id = Convert.ToInt32(lblEmailAddressID.Text);

                using (FormContext ctx = new FormContext())
                {
                    var emailAddress = ctx.EmailAddresses.Where(ea => ea.EmailAddressID == id).FirstOrDefault();

                    emailAddress.Name = ((TextBox)gvr.FindControl("txtNameEdit")).Text;
                    emailAddress.Address = ((TextBox)gvr.FindControl("txtAddressEdit")).Text;
                    emailAddress.Status = Convert.ToInt16(((RadioButtonList)gvr.FindControl("rblStatusEdit")).SelectedValue);
                    emailAddress.Company = ((DropDownList)gvr.FindControl("ddlCompanyEdit")).SelectedValue;

                    ctx.EmailAddresses.Attach(emailAddress);
                    ctx.Entry(emailAddress).State = EntityState.Modified;

                    ctx.SaveChanges();
                    gvEmailList.DataBind();

                    lblEmailMessage.Text = "";
                }
            }
            catch (Exception ex)
            {
                lblEmailMessage.Text = "Unable to update Email Address.  Please contact your system administrator.";
            }
        }