//JIRA-746 CHanges by Ravi on 05/03/2019 -- End

        protected void gvArtistDetails_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                if (e.CommandName == "saverow")
                {
                    if (!string.IsNullOrEmpty(hdnGridRowSelectedPrvious.Value))
                    {
                        int rowIndex = Convert.ToInt32(hdnGridRowSelectedPrvious.Value);

                        Page.Validate("GroupUpdate_" + rowIndex + "");
                        if (!Page.IsValid)
                        {
                            msgView.SetMessage("Invalid data entered.Please correct.", MessageType.Warning, PositionType.Auto);
                            return;
                        }

                        string artistId              = ((HiddenField)gvArtistDetails.Rows[rowIndex].FindControl("hdnArtistId")).Value;
                        string teamResponsibility    = ((DropDownList)gvArtistDetails.Rows[rowIndex].FindControl("ddlTeamResponsibility")).SelectedValue;
                        string managerResponsibility = ((DropDownList)gvArtistDetails.Rows[rowIndex].FindControl("ddlManagerResponsibility")).SelectedValue;

                        if (teamResponsibility == "-")
                        {
                            teamResponsibility = string.Empty;
                        }

                        if (managerResponsibility == "-")
                        {
                            managerResponsibility = string.Empty;
                        }

                        artistResponsibilityMaintenanceBL = new ArtistResponsibilityMaintenanceBL();
                        DataSet updatedData = artistResponsibilityMaintenanceBL.UpdateArtistData(artistId, teamResponsibility, managerResponsibility, Convert.ToString(Session["UserCode"]), hdnSearchText.Value, out errorId);
                        artistResponsibilityMaintenanceBL = null;

                        if (updatedData.Tables.Count != 0 && errorId != 2)
                        {
                            Session["ArtistResData"] = updatedData.Tables[0];

                            hdnChangeNotSaved.Value         = "N";
                            hdnGridRowSelectedPrvious.Value = null;
                            msgView.SetMessage("Artist details saved successfully.", MessageType.Success, PositionType.Auto);
                        }
                        else
                        {
                            msgView.SetMessage("Failed to save artist details.", MessageType.Warning, PositionType.Auto);
                        }
                    }
                }
                else if (e.CommandName == "cancelrow")
                {
                    if (Session["ArtistResData"] == null)
                    {
                        return;
                    }

                    DataTable dtArtistResData = Session["ArtistResData"] as DataTable;
                    BindGrid(dtArtistResData);

                    hdnChangeNotSaved.Value         = "N";
                    hdnGridRowSelectedPrvious.Value = null;
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler("Error in saving artist data.", ex.Message);
            }
        }
        protected void btnSaveChanges_Click(object sender, EventArgs e)
        {
            try
            {
                if (hdnChangeNotSaved.Value == "Y")
                {
                    int rowIndex = Convert.ToInt32(hdnGridRowSelectedPrvious.Value);

                    //Calculate the rowindex for validation
                    int rowIndexValidation = (gvArtistDetails.PageIndex * gvArtistDetails.PageSize) + rowIndex;

                    //Validate
                    Page.Validate("GroupUpdate_" + rowIndexValidation + "");
                    if (!Page.IsValid)
                    {
                        mpeSaveUndo.Hide();
                        msgView.SetMessage("Invalid data entered.Please correct.", MessageType.Warning, PositionType.Auto);
                        return;
                    }

                    string artistId              = ((HiddenField)gvArtistDetails.Rows[rowIndex].FindControl("hdnArtistId")).Value;
                    string teamResponsibility    = ((DropDownList)gvArtistDetails.Rows[rowIndex].FindControl("ddlTeamResponsibility")).SelectedValue;
                    string managerResponsibility = ((DropDownList)gvArtistDetails.Rows[rowIndex].FindControl("ddlManagerResponsibility")).SelectedValue;

                    if (teamResponsibility == "-")
                    {
                        teamResponsibility = string.Empty;
                    }

                    if (managerResponsibility == "-")
                    {
                        managerResponsibility = string.Empty;
                    }

                    artistResponsibilityMaintenanceBL = new ArtistResponsibilityMaintenanceBL();
                    DataSet updatedData = artistResponsibilityMaintenanceBL.UpdateArtistData(artistId, teamResponsibility, managerResponsibility, Convert.ToString(Session["UserCode"]), hdnSearchText.Value, out errorId);
                    artistResponsibilityMaintenanceBL = null;

                    if (updatedData.Tables.Count != 0 && errorId != 2)
                    {
                        Session["ArtistResData"] = updatedData.Tables[0];

                        hdnChangeNotSaved.Value         = "N";
                        hdnGridRowSelectedPrvious.Value = null;
                        msgView.SetMessage("Artist details saved successfully.", MessageType.Success, PositionType.Auto);
                    }
                    else
                    {
                        msgView.SetMessage("Failed to save artist details.", MessageType.Warning, PositionType.Auto);
                    }
                }
                else if (hdnInsertDataNotSaved.Value == "Y")
                {
                    Page.Validate("valInsertArtist");
                    if (!Page.IsValid)
                    {
                        msgView.SetMessage("Invalid data entered.Please correct.", MessageType.Warning, PositionType.Auto);
                        return;
                    }

                    artistResponsibilityMaintenanceBL = new ArtistResponsibilityMaintenanceBL();
                    DataSet updatedData = artistResponsibilityMaintenanceBL.InsertArtistData(txtArtistNameInsert.Text.Trim().ToUpper(), ddlDealTypeInsert.SelectedValue, ddlTeamRespInsert.SelectedValue, ddlManagerRespInsert.SelectedValue, Convert.ToString(Session["UserCode"]), hdnSearchText.Value, ddlDealType.SelectedValue, ddlResponsibility.SelectedValue, out errorId);
                    artistResponsibilityMaintenanceBL = null;

                    if (updatedData.Tables.Count != 0 && errorId == 0)
                    {
                        Session["ArtistResData"]           = updatedData.Tables[0];
                        txtArtistNameInsert.Text           = string.Empty;
                        ddlDealTypeInsert.SelectedIndex    = -1;
                        ddlTeamRespInsert.SelectedIndex    = -1;
                        ddlManagerRespInsert.SelectedIndex = -1;

                        gvArtistDetails.PageIndex = 0;
                        BindGrid(updatedData.Tables[0]);
                        hdnInsertDataNotSaved.Value = "N";
                        msgView.SetMessage("Artist details saved successfully.", MessageType.Success, PositionType.Auto);
                    }
                    else if (errorId == 1)
                    {
                        msgView.SetMessage("Artist with same name and deal type already exist.", MessageType.Success, PositionType.Auto);
                    }
                    else
                    {
                        msgView.SetMessage("Failed to save artist details.", MessageType.Warning, PositionType.Auto);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler("Error in saving artist data.", ex.Message);
            }
        }