private void BindPageFields()
    {
        QuoteRequestService objQuoteService      = new QuoteRequestService();
        JobDetailsService   objJobDetailsService = new JobDetailsService();

        QuoteRequest objQuoteReq = DataRepository.QuoteRequestProvider.GetByQuoteRequestId(QuoteRequestID);

        objQuoteService.DeepLoad(objQuoteReq, true, DeepLoadType.IncludeChildren
                                 , typeof(TList <JobDetails>), typeof(TList <CraQualifications>), typeof(TList <QuoteCandidates>));

        objJobDetailsService.DeepLoad(objQuoteReq.JobDetailsCollection[0], true,
                                      DeepLoadType.IncludeChildren, typeof(TList <JobDetailsStates>), typeof(TList <JobDetailsCountries>));

        JobDetails        objJobDetails = objQuoteReq.JobDetailsCollection[0];
        CraQualifications objCRAQual    = objQuoteReq.CraQualificationsCollection[0];

        txtJobDuties.Text = objJobDetails.JobDuties;
        if (objJobDetails.TentativeStartDate != null)
        {
            txtTentativeDate.Text = DateTime.Parse(objJobDetails.TentativeStartDate.ToString()).ToString("MM-dd-yyyy");
        }
        txtDurationContract.Text = objJobDetails.DurationContract;
        txtAvgDays.Text          = objJobDetails.AvgDays;

        foreach (JobDetailsCountries objJobDetailsCountries in objJobDetails.JobDetailsCountriesCollection)
        {
            lstBoxCountries.Items.FindByValue(objJobDetailsCountries.CountryId.ToString()).Selected = true;
        }

        foreach (JobDetailsStates objJobDetailsStates in objJobDetails.JobDetailsStatesCollection)
        {
            lstStates.Items.FindByValue(objJobDetailsStates.StateId.ToString()).Selected = true;
        }

        txtMinimumExp.Text        = objCRAQual.MinYearsExperience;
        txtTherapicExp.Text       = objCRAQual.ReqTherapeuticExperience;
        ddlFieldExp.SelectedValue = objCRAQual.FieldTypeExperience;
        txtPositionTitle.Text     = objCRAQual.PositionTitle;

        TList <QuoteCandidates> selectedCandidatesList = objQuoteReq.QuoteCandidatesCollection;

        //CachedCandidates = selectedCandidatesList.ToDataSet(false);
        BindCandidatesGrid();
        DataSet ds = CachedCandidates;

        foreach (QuoteCandidates qc in selectedCandidatesList)
        {
            ds.Tables[0].Rows.Find(qc.CandidateId);
            DataRow dr = ds.Tables[0].Rows.Find(qc.CandidateId);
            if (dr != null)
            {
                dr["Selected"] = true;
            }
        }
        CachedCandidates = ds;
        BindCandidatesGrid();//again bind grid
    }
    private void UpdateQuoteRequest()
    {
        QuoteRequestService objQuoteService      = new QuoteRequestService();
        JobDetailsService   objJobDetailsService = new JobDetailsService();

        QuoteRequest objQuoteReq = DataRepository.QuoteRequestProvider.GetByQuoteRequestId(QuoteRequestID);

        objQuoteService.DeepLoad(objQuoteReq, true, DeepLoadType.IncludeChildren
                                 , typeof(TList <JobDetails>), typeof(TList <CraQualifications>), typeof(TList <QuoteCandidates>));

        objJobDetailsService.DeepLoad(objQuoteReq.JobDetailsCollection[0], true,
                                      DeepLoadType.IncludeChildren, typeof(TList <JobDetailsStates>), typeof(TList <JobDetailsCountries>));

        JobDetails        objJobDetails = objQuoteReq.JobDetailsCollection[0];
        CraQualifications objCRAQual    = objQuoteReq.CraQualificationsCollection[0];

        objJobDetails.JobDuties = txtJobDuties.Text.Trim();
        if (txtTentativeDate.Text.Trim() != "")
        {
            objJobDetails.TentativeStartDate = DateTime.Parse(txtTentativeDate.Text);
        }
        else
        {
            objJobDetails.TentativeStartDate = null;
        }

        objJobDetails.DurationContract = txtDurationContract.Text;
        objJobDetails.AvgDays          = txtAvgDays.Text;

        objJobDetails.JobDetailsCountriesCollection.Clear();
        for (int i = 0; i < lstBoxCountries.Items.Count; i++)
        {
            if (lstBoxCountries.Items[i].Selected)
            {
                //JobDetailsCountries objJobDetailsSearched = objJobDetails.JobDetailsCountriesCollection.Find(JobDetailsCountriesColumn.CountryId, lstBoxCountries.Items[i].Value);
                //if (objJobDetailsSearched == null)
                //{
                JobDetailsCountries objJobDetailsCountries = new JobDetailsCountries();
                objJobDetailsCountries.CountryId = int.Parse(lstBoxCountries.Items[i].Value);
                objJobDetails.JobDetailsCountriesCollection.Add(objJobDetailsCountries);
                //}
            }
        }

        objJobDetails.JobDetailsStatesCollection.Clear();
        for (int i = 0; i < lstStates.Items.Count; i++)
        {
            if (lstStates.Items[i].Selected)
            {
                JobDetailsStates objJobDetailsStates = new JobDetailsStates();
                objJobDetailsStates.StateId = int.Parse(lstStates.Items[i].Value);
                objJobDetails.JobDetailsStatesCollection.Add(objJobDetailsStates);
            }
        }

        objCRAQual.MinYearsExperience       = txtMinimumExp.Text;
        objCRAQual.ReqTherapeuticExperience = txtTherapicExp.Text;
        if (ddlFieldExp.SelectedIndex != 0)
        {
            objCRAQual.FieldTypeExperience = ddlFieldExp.SelectedValue;
        }
        objCRAQual.PositionTitle = txtPositionTitle.Text.Trim();

        //objQuoteReq.JobDetailsCollection.Add(objJobDetails);
        //objQuoteReq.CraQualificationsCollection.Add(objCRAQual);

        objQuoteReq.QuoteCandidatesCollection.Clear();
        TList <QuoteCandidates> selectedCandidatesList = GetSelectedCandidates();

        if (selectedCandidatesList.Count > 0)
        {
            objQuoteReq.QuoteCandidatesCollection = selectedCandidatesList;
        }

        bool result = objQuoteService.DeepSave(objQuoteReq, ADB.Data.DeepSaveType.IncludeChildren,
                                               typeof(TList <JobDetails>), typeof(TList <CraQualifications>), typeof(TList <QuoteCandidates>));

        if (result)
        {
            objJobDetailsService.DeepSave(objJobDetails, DeepSaveType.IncludeChildren, typeof(TList <JobDetailsStates>), typeof(TList <JobDetailsCountries>));
        }

        //bool result = false;
        //objQuoteService.Save(objQuoteReq);

        MultiViewQuoteRequest.ActiveViewIndex = MultiViewQuoteRequest.ActiveViewIndex + 1;

        if (result)
        {
            lblSuccessfull.Text = "Your quote request is updated.";
        }
        else
        {
            lblSuccessfull.Text = "A problem accurred while trying to save your quote request.";
        }
    }