/// <summary>
        /// GetNextId
        /// </summary>
        /// <param name="ToDoListNavigatorTDS">ToDoListNavigatorTDS</param>
        /// <param name="currentToDoId">currentToDoId</param>
        /// <returns>nextToDoId</returns>
        public static int GetNextId(ToDoListNavigatorTDS toDoListNavigatorTDS, int currentToDoId)
        {
            int nextToDoId = currentToDoId;

            for (int i = 0; i < toDoListNavigatorTDS.ToDoListNavigator.DefaultView.Count; i++)
            {
                if ((int)toDoListNavigatorTDS.ToDoListNavigator.DefaultView[i]["ToDoID"] == currentToDoId)
                {
                    if (i == toDoListNavigatorTDS.ToDoListNavigator.DefaultView.Count - 1)
                    {
                        nextToDoId = currentToDoId;
                    }
                    else
                    {
                        nextToDoId = (int)toDoListNavigatorTDS.ToDoListNavigator.DefaultView[i + 1]["ToDoID"];
                    }
                    break;
                }

            }
            return nextToDoId;
        }
        /// <summary>
        /// GetPreviousId
        /// </summary>
        /// <param name="ToDoListNavigatorTDS">ToDoListNavigatorTDS</param>
        /// <param name="currentToDoId">currentToDoId</param>
        /// <returns>prevToDoId</returns>
        public static int GetPreviousId(ToDoListNavigatorTDS toDoListNavigatorTDS, int currentToDoId)
        {
            int prevToDoId = currentToDoId;

            for (int i = 0; i < toDoListNavigatorTDS.ToDoListNavigator.DefaultView.Count; i++)
            {
                if ((int)toDoListNavigatorTDS.ToDoListNavigator.DefaultView[i]["ToDoID"] == currentToDoId)
                {
                    if (i == 0)
                    {
                        prevToDoId = currentToDoId;
                    }
                    else
                    {
                        prevToDoId = (int)toDoListNavigatorTDS.ToDoListNavigator.DefaultView[i - 1]["ToDoID"];
                    }

                    break;
                }

            }

            return prevToDoId;
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!(Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_TODOLIST_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 toDoList_navigator2.aspx");
                }

                // Tag Page
                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfFmType.Value = "ToDoList";

                // Prepare initial data
                // ... For sortByList
                odsSortByList.DataBind();
                ddlSortBy.DataSourceID = "odsSortByList";
                ddlSortBy.DataValueField = "SortID";
                ddlSortBy.DataTextField = "Name";
                ddlSortBy.DataBind();

                // ... For state
                odsState.DataBind();
                ddlState.DataSourceID = "odsState";
                ddlState.DataValueField = "State";
                ddlState.DataTextField = "State";
                ddlState.DataBind();
                //ddlState.Items.Add("New & In Progress");

                // ... For
                odsViewForDisplayList.DataBind();
                ddlCondition1.DataSourceID = "odsViewForDisplayList";
                ddlCondition1.DataValueField = "ConditionID";
                ddlCondition1.DataTextField = "Name";
                ddlCondition1.DataBind();

                // ... For view ddl
                int companyId = Int32.Parse(hdfCompanyId.Value.Trim());
                string fmType = hdfFmType.Value;
                int loginId = Convert.ToInt32(Session["loginID"]);

                // If coming from
                // ... toDoList_navigator.aspx or toDoList_navigator2.aspx
                if ((Request.QueryString["source_page"] == "toDoList_navigator.aspx") || (Request.QueryString["source_page"] == "toDoList_navigator2.aspx"))
                {
                    RestoreNavigatorState();
                    toDoListNavigatorTDS = (ToDoListNavigatorTDS)Session["toDoListNavigatorTDS"];
                }

                // ... toDoList_edit.aspx, toDoList_summary.aspx or toDoList_delete.aspx
                if ((Request.QueryString["source_page"] == "toDoList_edit.aspx") || (Request.QueryString["source_page"] == "toDoList_summary.aspx") || (Request.QueryString["source_page"] == "toDoList_delete.aspx"))
                {
                    RestoreNavigatorState();

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

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

                // ... toDoList_delete.aspx, toDoList_summary.aspx or toDoList_edit.aspx
                if ((Request.QueryString["source_page"] == "toDoList_delete.aspx") || (Request.QueryString["source_page"] == "toDoList_summary.aspx") || (Request.QueryString["source_page"] == "toDoList_edit.aspx"))
                {
                    if (toDoListNavigatorTDS.ToDoListNavigator.Rows.Count == 0)
                    {
                        string url = "./toDoList_navigator.aspx?source_page=toDoList_navigator2.aspx&fm_type=" + hdfFmType.Value + GetNavigatorState() + "&no_results=yes";
                        Response.Redirect(url);
                    }
                }

                // For the grid
                grdToDoListNavigator.DataSource = toDoListNavigatorTDS.ToDoListNavigator;
                grdToDoListNavigator.DataBind();

                //... for the total rows
                if (toDoListNavigatorTDS.ToDoListNavigator.Rows.Count > 0)
                {
                    lblTotalRows.Text = "Total Rows: " + toDoListNavigatorTDS.ToDoListNavigator.Rows.Count;
                    lblTotalRows.Visible = true;
                }
                else
                {
                    lblTotalRows.Visible = false;
                }
            }
            else
            {
                // Restore TDS
                toDoListNavigatorTDS = (ToDoListNavigatorTDS)Session["toDoListNavigatorTDS"];

                // ... for the total rows
                if (toDoListNavigatorTDS.ToDoListNavigator.Rows.Count > 0)
                {
                    lblTotalRows.Text = "Total Rows: " + toDoListNavigatorTDS.ToDoListNavigator.Rows.Count;
                    lblTotalRows.Visible = true;
                }
                else
                {
                    lblTotalRows.Visible = false;
                }
            }
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            Page.Validate();

            if (Page.IsValid)
            {
                // Tag Page
                hdfBtnOrigin.Value = "Search";

                string url = "";

                // Delete store data
                Session.Contents.Remove("toDoListNavigatorTDS");

                // Get data from DA gateway
                toDoListNavigatorTDS = SubmitSearch();

                // Show results
                if (toDoListNavigatorTDS.ToDoListNavigator.Rows.Count > 0)
                {
                    // ... Store data
                    Session["toDoListNavigatorTDS"] = toDoListNavigatorTDS;

                    // ... Go to the results page
                    url = "./toDoList_navigator2.aspx?source_page=toDoList_navigator2.aspx" + GetNavigatorState();
                }
                else
                {
                    // ... Go to the search page
                    url = "./toDoList_navigator.aspx?source_page=toDoList_navigator2.aspx" + GetNavigatorState() + "&no_results=yes";
                }

                Response.Redirect(url);
            }
        }
 /// <summary>
 /// InitData
 /// </summary>
 protected override void InitData()
 {
     _data = new ToDoListNavigatorTDS();
 }