protected void btnSaveDetails_Click(object sender, EventArgs e)
 {
     try
     {
         ClientContactPersonDetailsBAL SaveclientContactPersonDetailsBAL = new ClientContactPersonDetailsBAL();
         DataTable clientContactPersonDetailsEntity = (DataTable)ViewState["ClientContactPersonDetails"];
         SaveclientContactPersonDetailsBAL.SaveClientContactPersonDetailsBAL(clientContactPersonDetailsEntity);
         grvAddMore.DataSource = null;
         grvAddMore.DataBind();
         ViewRecord(HrId, ClientId);
         Response.Write("<script language='javascript'>alert('Saved Client Contact Person Details Successfully')</script>");
     }
     catch (Exception)
     {
          throw;
     }
 }
        protected void grvView_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                ClientContactPersonDetailsBAL DeleteclientContactPersonDetailsBAL = new ClientContactPersonDetailsBAL();
                ClientContactPersonDetailsEntity clientContactPersonDetailsEntity = new ClientContactPersonDetailsEntity();
                var lblClientName = ((Label)grvView.Rows[e.RowIndex].FindControl("lblContactPersonName")).Text;

                var DecontactPersonId = ((Label)grvView.Rows[e.RowIndex].FindControl("lblContactPersonId")).Text;
                var DehrId = ((Label)grvView.Rows[e.RowIndex].FindControl("lblHrId")).Text;
                var DeclientId = ((Label)grvView.Rows[e.RowIndex].FindControl("lblClientId")).Text;
                //var contactPersonId = 1;
                //var hrId = 1;
                //var clientId = 1;
                // Assign values to the entities
                clientContactPersonDetailsEntity.ContactPersonId = Convert.ToInt32(DecontactPersonId);
                clientContactPersonDetailsEntity.HrId = Convert.ToInt32(DehrId);
                clientContactPersonDetailsEntity.ClientId = Convert.ToInt32(DeclientId);
                int result = DeleteclientContactPersonDetailsBAL.DeleteClientContactPersonDetailsBAL(clientContactPersonDetailsEntity);
                if (result > 0)
                {
                    Response.Write("<script language='javascript'>alert('Delete Client Contact Person Details Successfully')</script>");
                }
                else
                {
                    Response.Write("<script language='javascript'>alert('Client Contact Person Details won't Deleted')</script>");
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                grvView.EditIndex = -1;
                ViewRecord(HrId, ClientId);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (Session["HrId"] != null)
            //{
            //    if (Session["HrId"].ToString() != "")
            //    {
            //        HrId = Convert.ToString(Session["HrId"]);

                    if (!IsPostBack)
                    {
                        try
                        {
                            clientContactPersonDetails = new ClientContactPersonDetailsBAL();
                            ViewRecord(HrId,ClientId);
                            AddDefaultFirstRecord();
                        }
                        catch (Exception)
                        {
                            // throw;
                        }
                    }
                //}
            //}
        }
 private void ViewRecord(long HrId,long ClientId)
 {
     try
     {
         DataSet dsViewRecord = new DataSet();
         ClientContactPersonDetailsBAL ViewClientContactPersonDetails = new ClientContactPersonDetailsBAL();
         dsViewRecord = ViewClientContactPersonDetails.ViewClientContactPersonDetailsBAL(HrId, ClientId);
         if (dsViewRecord != null)
         {
             grvView.DataSource = dsViewRecord;
             grvView.DataBind();
         }
     }
     catch (Exception)
     {
         //throw;
     }
 }
        protected void grvView_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                ClientContactPersonDetailsBAL UpdateclientContactPersonDetailsBAL = new ClientContactPersonDetailsBAL();
                ClientContactPersonDetailsEntity clientContactPersonDetailsEntity = new ClientContactPersonDetailsEntity();
                //ViewRecord(HrId, ClientId);
                //GridView grView = (GridView)(sender as Control)e.Item.FindControl("grvView");
                //GridViewRow gvRow = (GridView)(sender as Control).Parent.Parent;
                GridView grView = (GridView)sender;
                //int UPhrId = Convert.ToInt32(grView.FooterRow.FindControl("lblHrId")as Label).Text);
                //int clientId = Convert.ToInt32(((Label)grView.FindControl("lblClientId")).Text);
                //int UPcontactPersonId = Convert.ToInt32((grView.FooterRow.FindControl("lblContactPersonId") as Label).Text);
                //Label lblClientName = (Label)e.Item.FindControl("lblClientName");
                //int UpContactPersonId = 1;
                var UPcontactPersonId = ((Label)grvView.Rows[e.RowIndex].FindControl("lblContactPersonId")).Text;
                var UPhrId = ((Label)grvView.Rows[e.RowIndex].FindControl("lblHrId")).Text;
                var UPclientId = ((Label)grvView.Rows[e.RowIndex].FindControl("lblClientId")).Text;
                string UPtxtName = ((TextBox)grvView.Rows[e.RowIndex].FindControl("txtName")).Text;
                string UPtxtDesignation = ((TextBox)grvView.Rows[e.RowIndex].FindControl("txtDesignation")).Text;
                string UPtxtEmail = ((TextBox)grvView.Rows[e.RowIndex].FindControl("txtEmail")).Text;
                var UPtxtContactNo = ((TextBox)grvView.Rows[e.RowIndex].FindControl("txtContactNo")).Text;
                string UPrblistIsActive = ((RadioButtonList)grvView.Rows[e.RowIndex].FindControl("rblistIsActive")).SelectedItem.Text;

                // Assign values to the entities
                clientContactPersonDetailsEntity.ContactPersonId = Convert.ToInt32(UPcontactPersonId);
                clientContactPersonDetailsEntity.HrId = Convert.ToInt32(UPhrId);
                clientContactPersonDetailsEntity.ClientId = Convert.ToInt32(UPclientId);
                clientContactPersonDetailsEntity.ContactPersonName = UPtxtName;
                clientContactPersonDetailsEntity.Designation = UPtxtDesignation;
                clientContactPersonDetailsEntity.EmailId = UPtxtEmail;
                clientContactPersonDetailsEntity.ContactNo = Convert.ToInt32(UPtxtContactNo);
                //Convert.ToInt32(ddlFunctionalArea.SelectedValue);
                clientContactPersonDetailsEntity.IsActive = UPrblistIsActive;
                // Saving data to the database
                int result = UpdateclientContactPersonDetailsBAL.UpdateClientContactPersonDetailsBAL(clientContactPersonDetailsEntity);
                if (result > 0)
                {
                    Response.Write("<script language='javascript'>alert('Update Client Contact Person Details Successfully')</script>");
                }
                else
                {
                    Response.Write("<script language='javascript'>alert('Client Contact Person Details won't Saved')</script>");
                }
            }
            catch (Exception)
            {
                //throw;
            }
            finally
            {
                grvView.EditIndex = -1;
                ViewRecord(HrId, ClientId);
            }
        }