void pager_GetBaseUrl(object sender, GetBaseUrlEventArgs e)
 {
     e.BaseUrl = this.GetBaseUrl();
 }
Example #2
0
        protected override void Render(HtmlTextWriter output)
        {
            if (this.EventMode == true)
            {
                LinkButton first = (LinkButton)this.FindControl("first");
                if (this.CurrentPageNo == 0)
                    first.Visible = false;

                LinkButton prev = (LinkButton)this.FindControl("prev");
                if (this.CurrentPageNo == 0)
                    prev.Visible = false;

                ButtonBegin("first");
                LinkButton next = (LinkButton)this.FindControl("next");
                if (this.CurrentPageNo >= this.TotalCount - 1)
                    next.Visible = false;

                int nStart = 0;
                int nEnd = 0;
                nStart = this.CurrentPageNo - 4;
                nEnd = this.CurrentPageNo + 4;

                bool bHead = false;
                if (nStart < 0)
                {
                    nStart = 0;
                    nEnd = nStart + 9;
                    bHead = true;
                }

                if (nStart == 0)
                    first.Visible = false;

                if (nEnd > this.TotalCount - 1)
                {
                    nEnd = this.TotalCount - 1;
                    if (bHead == false)
                    {
                        nStart = nEnd - 9;
                        if (nStart < 0)
                            nStart = 0;
                    }
                }

                int nLength = nEnd - nStart + 1;
                List<int> pagenos = new List<int>();

                for (int i = 0; i < 10; i++)
                {
                    string strID = "goto_" + i.ToString();
                    LinkButton link = (LinkButton)this.FindControl(strID);
                    if (i >= nLength)
                    {
                        link.Text = "";
                        link.Visible = false;
                        pagenos.Add(-1);
                    }
                    else
                    {
                        if (this.CurrentPageNo == nStart + i)
                            link.CssClass += " current";
                        link.Text = (nStart + i + 1).ToString();
                        link.Visible = true;
                        pagenos.Add(nStart + i);
                    }
                }

                // 最后一个页
                {
                    string strID = "goto_10";
                    LinkButton link = (LinkButton)this.FindControl(strID);
                    if (nEnd != this.TotalCount - 1)
                    {
                        link.Text =
                            ((nEnd != this.TotalCount - 2) ? "..." : "")
                            + (this.TotalCount - 1 + 1).ToString();
                        link.Visible = true;
                        pagenos.Add(this.TotalCount - 1);
                    }
                    else
                    {
                        link.Visible = false;
                        pagenos.Add(-1);
                    }
                }

                string strLine = (this.CurrentPageNo - 1).ToString()
                    + "," + (this.CurrentPageNo + 1).ToString();
                for (int i = 0; i < pagenos.Count; i++)
                {
                    strLine += "," + pagenos[i].ToString();
                }
                this.PageNoList = strLine;

                base.Render(output);
            }
            else
            {
                // URL模式

                HyperLink first = (HyperLink)this.FindControl("first");
                if (this.CurrentPageNo == 0)
                    first.Visible = false;

                HyperLink prev = (HyperLink)this.FindControl("prev");
                if (this.CurrentPageNo == 0)
                    prev.Visible = false;

                HyperLink next = (HyperLink)this.FindControl("next");
                if (this.CurrentPageNo >= this.TotalCount - 1)
                    next.Visible = false;

                int nStart = 0;
                int nEnd = 0;
                nStart = this.CurrentPageNo - 4;
                nEnd = this.CurrentPageNo + 4;

                bool bHead = false;
                if (nStart < 0)
                {
                    nStart = 0;
                    nEnd = nStart + 9;
                    bHead = true;
                }

                if (nStart == 0)
                    first.Visible = false;

                if (nEnd > this.TotalCount - 1)
                {
                    nEnd = this.TotalCount - 1;
                    if (bHead == false)
                    {
                        nStart = nEnd - 9;
                        if (nStart < 0)
                            nStart = 0;
                    }
                }

                GetBaseUrlEventArgs e = new GetBaseUrlEventArgs();
                this.GetBaseUrl(this, e);
                string strBaseUrl = RemoveParameter(e.BaseUrl, this.PageNoParaName);

                int nLength = nEnd - nStart + 1;
                List<int> pagenos = new List<int>();

                for (int i = 0; i < 10; i++)
                {
                    string strID = "goto_" + i.ToString();
                    HyperLink link = (HyperLink)this.FindControl(strID);
                    if (i >= nLength)
                    {
                        link.Text = "";
                        link.Visible = false;
                        link.NavigateUrl = "";
                        //pagenos.Add(-1);
                    }
                    else
                    {
                        if (this.CurrentPageNo == nStart + i)
                            link.CssClass += " current";
                        link.Text = (nStart + i + 1).ToString();
                        link.Visible = true;
                        link.NavigateUrl = GetUrl(nStart + i, strBaseUrl, this.PageNoParaName);
                        //pagenos.Add(nStart + i);
                    }
                }

                // 最后一个页
                {
                    string strID = "goto_10";
                    HyperLink link = (HyperLink)this.FindControl(strID);
                    if (nEnd != this.TotalCount - 1)
                    {
                        link.Text =
                            ((nEnd != this.TotalCount - 2) ? "..." : "")
                            + (this.TotalCount - 1 + 1).ToString();
                        link.Visible = true;
                        link.NavigateUrl = GetUrl(this.TotalCount - 1, strBaseUrl, this.PageNoParaName);
                        //pagenos.Add(this.TotalCount - 1);
                    }
                    else
                    {
                        link.Visible = false;
                        link.NavigateUrl = "";
                        //pagenos.Add(-1);
                    }
                }

                if (first.Visible == true)
                    first.NavigateUrl = GetUrl(0, strBaseUrl, this.PageNoParaName);
                if (prev.Visible == true)
                    prev.NavigateUrl = GetUrl(CurrentPageNo - 1, strBaseUrl, this.PageNoParaName);
                if (next.Visible == true)
                    next.NavigateUrl = GetUrl(CurrentPageNo + 1, strBaseUrl, this.PageNoParaName);

                base.Render(output);
            }
        }
Example #3
0
        protected override void Render(HtmlTextWriter output)
        {
            if (this.EventMode == true)
            {
                LinkButton first = (LinkButton)this.FindControl("first");
                if (this.CurrentPageNo == 0)
                {
                    first.Visible = false;
                }

                LinkButton prev = (LinkButton)this.FindControl("prev");
                if (this.CurrentPageNo == 0)
                {
                    prev.Visible = false;
                }

                ButtonBegin("first");
                LinkButton next = (LinkButton)this.FindControl("next");
                if (this.CurrentPageNo >= this.TotalCount - 1)
                {
                    next.Visible = false;
                }

                int nStart = 0;
                int nEnd   = 0;
                nStart = this.CurrentPageNo - 4;
                nEnd   = this.CurrentPageNo + 4;

                bool bHead = false;
                if (nStart < 0)
                {
                    nStart = 0;
                    nEnd   = nStart + 9;
                    bHead  = true;
                }

                if (nStart == 0)
                {
                    first.Visible = false;
                }

                if (nEnd > this.TotalCount - 1)
                {
                    nEnd = this.TotalCount - 1;
                    if (bHead == false)
                    {
                        nStart = nEnd - 9;
                        if (nStart < 0)
                        {
                            nStart = 0;
                        }
                    }
                }

                int        nLength = nEnd - nStart + 1;
                List <int> pagenos = new List <int>();

                for (int i = 0; i < 10; i++)
                {
                    string     strID = "goto_" + i.ToString();
                    LinkButton link  = (LinkButton)this.FindControl(strID);
                    if (i >= nLength)
                    {
                        link.Text    = "";
                        link.Visible = false;
                        pagenos.Add(-1);
                    }
                    else
                    {
                        if (this.CurrentPageNo == nStart + i)
                        {
                            link.CssClass += " current";
                        }
                        link.Text    = (nStart + i + 1).ToString();
                        link.Visible = true;
                        pagenos.Add(nStart + i);
                    }
                }

                // 最后一个页
                {
                    string     strID = "goto_10";
                    LinkButton link  = (LinkButton)this.FindControl(strID);
                    if (nEnd != this.TotalCount - 1)
                    {
                        link.Text =
                            ((nEnd != this.TotalCount - 2) ? "..." : "")
                            + (this.TotalCount - 1 + 1).ToString();
                        link.Visible = true;
                        pagenos.Add(this.TotalCount - 1);
                    }
                    else
                    {
                        link.Visible = false;
                        pagenos.Add(-1);
                    }
                }

                string strLine = (this.CurrentPageNo - 1).ToString()
                                 + "," + (this.CurrentPageNo + 1).ToString();
                for (int i = 0; i < pagenos.Count; i++)
                {
                    strLine += "," + pagenos[i].ToString();
                }
                this.PageNoList = strLine;

                base.Render(output);
            }
            else
            {
                // URL模式

                HyperLink first = (HyperLink)this.FindControl("first");
                if (this.CurrentPageNo == 0)
                {
                    first.Visible = false;
                }

                HyperLink prev = (HyperLink)this.FindControl("prev");
                if (this.CurrentPageNo == 0)
                {
                    prev.Visible = false;
                }

                HyperLink next = (HyperLink)this.FindControl("next");
                if (this.CurrentPageNo >= this.TotalCount - 1)
                {
                    next.Visible = false;
                }

                int nStart = 0;
                int nEnd   = 0;
                nStart = this.CurrentPageNo - 4;
                nEnd   = this.CurrentPageNo + 4;

                bool bHead = false;
                if (nStart < 0)
                {
                    nStart = 0;
                    nEnd   = nStart + 9;
                    bHead  = true;
                }

                if (nStart == 0)
                {
                    first.Visible = false;
                }

                if (nEnd > this.TotalCount - 1)
                {
                    nEnd = this.TotalCount - 1;
                    if (bHead == false)
                    {
                        nStart = nEnd - 9;
                        if (nStart < 0)
                        {
                            nStart = 0;
                        }
                    }
                }

                GetBaseUrlEventArgs e = new GetBaseUrlEventArgs();
                this.GetBaseUrl(this, e);
                string strBaseUrl = RemoveParameter(e.BaseUrl, this.PageNoParaName);

                int        nLength = nEnd - nStart + 1;
                List <int> pagenos = new List <int>();

                for (int i = 0; i < 10; i++)
                {
                    string    strID = "goto_" + i.ToString();
                    HyperLink link  = (HyperLink)this.FindControl(strID);
                    if (i >= nLength)
                    {
                        link.Text        = "";
                        link.Visible     = false;
                        link.NavigateUrl = "";
                        //pagenos.Add(-1);
                    }
                    else
                    {
                        if (this.CurrentPageNo == nStart + i)
                        {
                            link.CssClass += " current";
                        }
                        link.Text        = (nStart + i + 1).ToString();
                        link.Visible     = true;
                        link.NavigateUrl = GetUrl(nStart + i, strBaseUrl, this.PageNoParaName);
                        //pagenos.Add(nStart + i);
                    }
                }

                // 最后一个页
                {
                    string    strID = "goto_10";
                    HyperLink link  = (HyperLink)this.FindControl(strID);
                    if (nEnd != this.TotalCount - 1)
                    {
                        link.Text =
                            ((nEnd != this.TotalCount - 2) ? "..." : "")
                            + (this.TotalCount - 1 + 1).ToString();
                        link.Visible     = true;
                        link.NavigateUrl = GetUrl(this.TotalCount - 1, strBaseUrl, this.PageNoParaName);
                        //pagenos.Add(this.TotalCount - 1);
                    }
                    else
                    {
                        link.Visible     = false;
                        link.NavigateUrl = "";
                        //pagenos.Add(-1);
                    }
                }

                if (first.Visible == true)
                {
                    first.NavigateUrl = GetUrl(0, strBaseUrl, this.PageNoParaName);
                }
                if (prev.Visible == true)
                {
                    prev.NavigateUrl = GetUrl(CurrentPageNo - 1, strBaseUrl, this.PageNoParaName);
                }
                if (next.Visible == true)
                {
                    next.NavigateUrl = GetUrl(CurrentPageNo + 1, strBaseUrl, this.PageNoParaName);
                }

                base.Render(output);
            }
        }