如何用asp.net2.0 c# 实现新闻分页,每个分页都生成html文件

解决方案 »

  1.   

    添加新闻时,通过模板生成静态页。保存文件名,通过伪静态实现分页
    参考
    http://www.cnblogs.com/supers/articles/1276387.html
      

  2.   

    新闻列表静态分页,
    若没10条为1页,读出新闻数量,除以10得到的数值进行循环,
    用sql读出数据 进行分页
     //得到新闻数量
                RCount = Convert.ToInt32(GetValueByKey("count(id)", "tbnews", pStr));            pStr = "from [tbnews] where site='" + site + "' and " + pStr;            if (RCount % pagesize == 0)
                    PCount = RCount / pagesize;
                else
                    PCount = (RCount / pagesize) + 1;            if (PCount > 0)
                {
                    for (int i = 1; i < PCount + 1; i++)
                    {                    if (data.GetTableVaule("tbSiteSort", "id", "pid", Convert.ToInt32(id)) == "no")
                        {
                            string wStr = "select top " + pagesize + " [ID],sort,title,color,Topsign,sdate,content,picture,ftitle  " + pStr;                        if (i == 1)
                                wStr += oStr;
                            else
                            {
                                wStr += " and [ID] not in (select top " + pagesize * (i - 1) + " [ID] " + pStr + oStr + ")";
                                wStr += oStr;
                            }                        DataTable dt1 = data.GetDataTable(wStr);
                            if (dt.Rows.Count > 0)
                            {
                                strhttp = strhttp1.Replace("{$body$}", make.NList(dt1, 85));
                            }
                        }                    strhttp = strhttp.Replace("{$PageNumNav$}", make.getPageNav(i, PCount, id + "_"));
                        path = Server.MapPath("/zh/news/" + dt.Rows[0][1] + "");                    if (!System.IO.Directory.Exists(path))
                        {
                            System.IO.Directory.CreateDirectory(path);
                        }                    if (i == 1)
                        {
                            newHtml = Request.PhysicalApplicationPath + "\\/zh/news/" + dt.Rows[0][1] + "\\default.Htm";
                            sw = new System.IO.StreamWriter(newHtml, false, System.Text.Encoding.GetEncoding("GB2312"));
                            sw.Write(strhttp);
                            sw.Close();
                        }
                        newHtml = Request.PhysicalApplicationPath + "\\/zh/news/" + dt.Rows[0][1] + "/\\" + id + "_" + i + ".Htm";
                        sw = new System.IO.StreamWriter(newHtml, false, System.Text.Encoding.GetEncoding("GB2312"));
                        sw.Write(strhttp);
                        sw.Close();
                    }
                }
      

  3.   

    //分页函数《开始》
            public string getPageNav(int iCurrentPage, int iPageCount, string Http)
            {
                string OutStr = "";            if (iCurrentPage == 1)
                {
                    OutStr += "&nbsp;<font color=\"#666666\">[首页]</font>&nbsp;<font color=\"#666666\">[上一页]</font>";
                }
                else
                {
                    OutStr += "&nbsp;<a href='" + Http + "1.Htm'><font color=\"#800000\">[首页]</font></a>";
                    OutStr += "&nbsp;<a href='" + Http + (iCurrentPage - 1) + ".Htm'><font color=\"#800000\">[上一页]</font></a>";
                }
                OutStr += "&nbsp;";            if (iCurrentPage < iPageCount)
                {
                    OutStr += "<a href='" + Http + (iCurrentPage + 1) + ".Htm'><font color=\"#800000\">[下一页]</font></a>";
                    OutStr += "&nbsp;<a href='" + Http + iPageCount + ".Htm'><font color=\"#800000\">[尾页]</font></a>";
                }
                else
                {
                    OutStr += "<font color=\"#666666\">[下一页]</font>&nbsp;<font color=\"#666666\">[尾页]</font>";
                }            OutStr += "&nbsp;&nbsp;" + iCurrentPage + "/" + iPageCount + "&nbsp;&nbsp;";
                OutStr += "<INPUT TYPE=text class=iptA size=3 value=" + iCurrentPage + " onmouseover='this.focus();this.select()' NAME=PGNumber> <INPUT TYPE=button id=button1 name=button1 class=btnA value=GO onclick=\"if(document.all.PGNumber.value>0 && document.all.PGNumber.value<=" + iPageCount + "){window.location='" + Http + "'+document.all.PGNumber.value+'.Htm'}\" onmouseover='this.focus()' onfocus='this.blur()'>&nbsp;";
                return OutStr;
            }
            //分页函数《结束》
      

  4.   

    生成第一页可以,关键是第二页的数据是怎么读取出来,然后在写入html文件中
      

  5.   

    wStr += " and [ID] not in (select top " + pagesize * (i - 1) + " [ID] " + pStr + oStr + ")"; 
    这个sql语句就是读出第一页之后的数据
      

  6.   

    其实个人感觉你生成这个分页没有必要,如果你数据量很大,难道你添加一条信息或删除一条信息都要重新再生成一次吗?再说了就算你生成了,查找时你不还是得用动态的....所以个人感觉没有必要把分页这个弄成静态的...只要把详细页面生成静态的就成了!当然如果你觉得列表页后缀不是html 的心里不爽,你完全可以在html页面里用ajax来实现呀....
      

  7.   

    如果你为了这点小事再弄成 伪静态的那性能就更差了....用ajax是首选....
      

  8.   

    可以做个HTML模板 用I/O读取后 替换内容 然后再生产SHTML
    分页判断正文字数 和生产多少页
      

  9.   

    make.getPageNav(i, PCount, id + "_")make从什么地方来的