您的位置:首页 > Web前端 > JavaScript

js翻页,已转成c#的

2015-11-12 10:35 393 查看
 string page = "";

            page = Request.QueryString["page"];

            if (string.IsNullOrEmpty(page))

            {

                page = "1";

            }

            DataTable rst0 = null;

            if (page == "1")

            {

                rst0 = DAL.SQLiteHelper.ExecuteDataTable(DAL.SQLiteHelper.CONN_STRING, CommandType.Text, sqlt);

                Session["dvlistt"] = rst0;

            }

            if (Session["dvlistt"] == null)

            {

                rst0 = DAL.SQLiteHelper.ExecuteDataTable(DAL.SQLiteHelper.CONN_STRING, CommandType.Text, sqlt);

                Session["dvlistt"] = rst0;

            }

            else

            {

                rst0 = (DataTable)Session["dvlistt"];

            }

            

            int zolpage = 0, curend = 0, fys = 12;

            zolpage = rst0.Rows.Count;

            if ((int.Parse(page) - 1) + fys < zolpage)

            {

                curend = (int.Parse(page) - fys) + 1;

            }

            else

            {

                curend = zolpage;

            }

 

            for (int i = int.Parse(page) - 1; i < curend; i++)

            {

                sb.AppendLine("<li> <a href=\"product_title_" + rst0.Rows[i]["id"] + ".aspx\"><img src=\"" + rst0.Rows[i]["img1"] + "\" width=\"120\" height=\"125\" /></a>");

                sb.AppendLine("<h2><a href=\"product_title_" + rst0.Rows[i]["id"] + ".aspx\" title=\"" + rst0.Rows[i]["title"] + "\">" + rst0.Rows[i]["title"] + "</a></h2>");

                sb.AppendLine("</li>");

            }

 

 

-----------------------上面是展示列表

 

 

     sb.AppendLine(GetPageBar(int.Parse(page), zolpage,""));

 

---------------------调用翻页-------------

 

 

 

 

-------------------------------翻页函数,需

 

 

private string GetPageBar(int currentPageIndex, int pageCount, string others)

        {

            string strHtml = "";

            int endPage = 0;

            int prevpage = currentPageIndex - 1, nextpage = currentPageIndex + 1;

            strHtml += "<div class=\"xfenye s_12bh\">";

            if (prevpage < 1)

            {

                strHtml += "<a href=\"#\">首页</a>";

                strHtml += "<a href=\"#\">前页</a>";

            }

            else

            {

                strHtml += "<a href=\"" + others + "\\page-1\">首页</a>";

                strHtml += "<a href=\"" + others + "\\page-" + prevpage + "\">前页</a>";

            }

            if (currentPageIndex != 1)

                strHtml += "<a href=\"" + others + "\\page-1\">1</a>";

            if (currentPageIndex >= 5)

                strHtml += "<a>……</a>";

            if (pageCount > currentPageIndex + 4)

            {

                endPage = currentPageIndex + 4;

            }

            else

            {

                endPage = pageCount;

            }

            for (int i = currentPageIndex - 2; i <= endPage; i++)

            {

                if (i > 0)

                {

                    if (i == currentPageIndex)

                    {

                        strHtml += "<a href=\"#\" style=\"color:#F00\">" + i.ToString() + "</a>";

                    }

                    else

                    {

            
4000
            if (i != 1 && i != pageCount)

                        {

                            strHtml += "<a href=\"" + others + "\\page-" + i.ToString() + "\">" + i.ToString() + "</a>";

                        }

                    }

                }

            }

            if (currentPageIndex + 5 < pageCount) strHtml += "<a>……</a>";

            if (currentPageIndex != pageCount) strHtml += "<a href=\"" + others + "\\page-" + pageCount.ToString() + "\">" + pageCount.ToString() + "</a>";

            if (nextpage > pageCount)

            {

                strHtml += "<a href=\"#\">后页</a>";

                strHtml += "<a href=\"#\">尾页</a>";

            }

            else

            {

                strHtml += "<a href=\"" + others + "\\page-" + nextpage + "\">后页</a>";

                strHtml += "<a href=\"" + others + "\\page-" + pageCount + "\">尾页</a>";

            }

            strHtml += "</div>";

            return strHtml;

        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: