protected void rgGrid_InsertCommand(object sender, GridCommandEventArgs e) { try { UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID); Label errorMsg = (Label)userControl.FindControl("lblErrorMessage"); ClsEquipment oEquipment = populateObj(userControl); string insertMsg = ""; if (IsValid) { if (oEquipment != null) { insertMsg = eq.InsertEquipment(oEquipment); if (insertMsg == "") { pnlsuccess.Visible = true; lblSuccess.Text = "Successfully Added New CloseReason " + oEquipment.Equipment; } else { errorMsg.Visible = true; errorMsg.Text = insertMsg; e.Canceled = true; } } } else { // display error errorMsg.Visible = true; errorMsg.Text = "Please enter Required fields"; e.Canceled = true; } } catch (Exception ex) { pnlDanger.Visible = true; lblDanger.Text = ex.Message.ToString(); e.Canceled = true; } }