/// <summary>
        /// GetNextId
        /// </summary>
        /// <param name="subcontractorHoursNavigatorTDS">subcontractorHoursNavigatorTDS</param>
        /// <param name="currentRefID">currentRefID</param>
        /// <returns>nextRefID</returns>
        public static int GetNextId(SubcontractorHoursNavigatorTDS subcontractorHoursNavigatorTDS, int currentRefID)
        {
            int nextRefID = currentRefID;

            for (int i = 0; i < subcontractorHoursNavigatorTDS.SubcontractorHoursNavigator.DefaultView.Count; i++)
            {
                if ((int)subcontractorHoursNavigatorTDS.SubcontractorHoursNavigator.DefaultView[i]["RefID"] == currentRefID)
                {
                    if (i == subcontractorHoursNavigatorTDS.SubcontractorHoursNavigator.DefaultView.Count - 1)
                    {
                        nextRefID = currentRefID;
                    }
                    else
                    {
                        nextRefID = (int)subcontractorHoursNavigatorTDS.SubcontractorHoursNavigator.DefaultView[i + 1]["RefID"];
                    }
                    break;
                }
            }

            return nextRefID;
        }
        // ////////////////////////////////////////////////////////////////////////
        // PRIVATE METHODS
        //
        /// <summary>
        /// GetPreviousId
        /// </summary>
        /// <param name="subcontractorHoursNavigatorTDS">subcontractorHoursNavigatorTDS</param>
        /// <param name="currentRefID">currentRefID</param>
        /// <returns>prevRefID</returns>
        public static int GetPreviousId(SubcontractorHoursNavigatorTDS subcontractorHoursNavigatorTDS, int currentRefID)
        {
            int prevRefID = currentRefID;

            for (int i = 0; i < subcontractorHoursNavigatorTDS.SubcontractorHoursNavigator.DefaultView.Count; i++)
            {
                if ((int)subcontractorHoursNavigatorTDS.SubcontractorHoursNavigator.DefaultView[i]["RefID"] == currentRefID)
                {
                    if (i == 0)
                    {
                        prevRefID = currentRefID;
                    }
                    else
                    {
                        prevRefID = (int)subcontractorHoursNavigatorTDS.SubcontractorHoursNavigator.DefaultView[i - 1]["RefID"];
                    }

                    break;
                }
            }

            return prevRefID;
        }
 /// <summary>
 /// InitData
 /// </summary>
 protected override void InitData()
 {
     _data = new SubcontractorHoursNavigatorTDS();
 }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                if (!(Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_SUBCONTRACTOR_HOURS_ADMIN"])))
                {
                    // Security check
                    if (!(Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_SUBCONTRACTOR_HOURS_VIEW"])))
                    {
                        Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                    }

                    // Validate query string
                    if ((string)Request.QueryString["source_page"] == null)
                    {
                        Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in subcontractor_hours_navigator.aspx");
                    }
                }

                // Tag Page
                hdfCompanyId.Value = Session["companyID"].ToString();
                tkrdpStartDate.SelectedDate = DateTime.Now;
                tkrdpEndDate.SelectedDate = DateTime.Now;

                Session.Remove("subcontractorHoursNavigatorNewDummy");

                RestoreNavigatorState();

                // If coming from
                // ... subcontractor_hours_navigator.aspx or subcontractor_hours_navigator2.aspx
                if ((Request.QueryString["source_page"] == "subcontractor_hours_navigator.aspx") || (Request.QueryString["source_page"] == "subcontractor_hours_navigator2.aspx"))
                {
                    subcontractorHoursNavigatorTDS = (SubcontractorHoursNavigatorTDS)Session["subcontractorHoursNavigatorTDS"];
                }

                // ... subcontractor_hours_edit.aspx, subcontractor_hours_summary.aspx or subcontractor_hours_delete.aspx
                if ((Request.QueryString["source_page"] == "subcontractor_hours_edit.aspx") || (Request.QueryString["source_page"] == "subcontractor_hours_summary.aspx") || (Request.QueryString["source_page"] == "subcontractor_hours_delete.aspx"))
                {
                    RestoreNavigatorState();

                    if (Request.QueryString["update"] == "no")
                    {
                        subcontractorHoursNavigatorTDS = (SubcontractorHoursNavigatorTDS)Session["subcontractorHoursNavigatorTDS"];
                    }
                    else
                    {
                        // ... Delete store data
                        Session.Contents.Remove("subcontractorHoursNavigatorTDS");

                        // ... Search data with updates
                        subcontractorHoursNavigatorTDS = SubmitSearchBySubcontractor();

                        // ... store datasets
                        Session["subcontractorHoursNavigatorTDS"] = subcontractorHoursNavigatorTDS;
                    }
                }

                Session["subcontractorHoursNavigatorTDS"] = subcontractorHoursNavigatorTDS;
                Session["subcontractorHoursNavigator"] = subcontractorHoursNavigatorTDS.SubcontractorHoursNavigator;

                // ... for the total rows
                if (subcontractorHoursNavigatorTDS.SubcontractorHoursNavigator.Rows.Count > 0)
                {
                    lblTotalRows.Text = "Total Rows: " + subcontractorHoursNavigatorTDS.SubcontractorHoursNavigator.Rows.Count;
                    lblTotalRows.Visible = true;
                }
                else
                {
                    lblTotalRows.Visible = false;
                }
            }
            else
            {
                // Restore searched data (if any)
                subcontractorHoursNavigatorTDS = (SubcontractorHoursNavigatorTDS)Session["subcontractorHoursNavigatorTDS"];
                subcontractorHoursNavigator = subcontractorHoursNavigatorTDS.SubcontractorHoursNavigator;

                // ... for the total rows
                if (subcontractorHoursNavigatorTDS.SubcontractorHoursNavigator.Rows.Count > 0)
                {
                    lblTotalRows.Text = "Total Rows: " + subcontractorHoursNavigatorTDS.SubcontractorHoursNavigator.Rows.Count;
                    lblTotalRows.Visible = true;
                }
                else
                {
                    lblTotalRows.Visible = false;
                }
            }
        }