ASP.Net產生靜態頁面帶分頁

來源:互聯網
上載者:User

模板頁

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div style="width: 417px; height: 54px" align="center">
<br />
Title
</div>
<div style="width: 417px; height: 8px">
瀏覽 <font color="red">
<script src="http://localhost/.Net/NewsFiles/ClickCount.aspx?NewsId=NewsId"> </script>
</font>次 Time
</div>
<div style="width: 417px; height: 100px">
Content
</div>
<div style="width: 416px; height: 9px">
Pager
</div>
<div style="width: 416px; height: 8px">
<form id="form1" action="../AddComment.aspx" style="margin: 0px">
<input id="Text1" type="text" />
<img id="Image1" src="http://www.dwww.cn/UserInfo/CheckCode.aspx" />
<br />
<textarea id="CommentContent" cols="20" rows="2"> </textarea>
<br />
<input id="NewsId" type="hidden" value="NewsId" />
<input id="Button1" type="submit" value="button" />
<a href="http://www.dwww.cn/News/Display.aspx?NewsId=NewsId">查看更多評論 </a>
</form>
</div>
</body>
</html>

產生代碼:

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.IO;public partial class Add : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {    }    protected void Button1_Click(object sender, EventArgs e)    {        string content = "發的發生的方法的是否 的|方式大範德薩費點事的的";        string htmlStr = string.Empty;        string[] contentStr = content.Split('|');        string strTable = " <table> <tr> <td>upUrl </td> <td>Number </td> <td>downUrl </td> </tr> </table>";//上下頁表格,注意此處的upUrl(上一頁),Number(頁碼分頁),downUrl(下一頁)         int PageNumber = contentStr.Length;        for (int m = 0; m <PageNumber; m++)        {            string numberStr = string.Empty;            string filePath=string.Empty;            for (int i = 1; i <= PageNumber; i++)            {                if (i == 1)                {                    numberStr += "[<a href='" + DateTime.Now.ToString("yyyymmddhhmmss") + ".html" + "'>" + i + "</a>]";                }                else                {                    int p = i-1;                    numberStr += "[<a href='" + DateTime.Now.ToString("yyyymmddhhmmss") + "_"+p+".html" + "'>" + i + "</a>]";                                   }            }            if (m==0)            {               filePath = Server.MapPath(".") + "//" + DateTime.Now.ToString("yyyymmddhhmmss") + ".html";            }            else            {                filePath = Server.MapPath(".") + "//" + DateTime.Now.ToString("yyyymmddhhmmss") + "_" + m + ".html";            }            using (StreamReader sr = new StreamReader(Server.MapPath("NewsFiles/template.html"),System.Text.Encoding.GetEncoding("gb2312")))             {                 htmlStr= sr.ReadToEnd();            }            htmlStr = htmlStr.Replace("Title", "產生靜態頁面分頁");            htmlStr = htmlStr.Replace("NewsId", "11");            htmlStr = htmlStr.Replace("Time", DateTime.Now.ToString("yyyy/MM/dd"));            htmlStr = htmlStr.Replace("Content", contentStr[m]);            htmlStr=htmlStr.Replace("Pager", strTable.Replace("Number", numberStr));            FileInfo file=new FileInfo (filePath);            Stream fs=file.OpenWrite();            using (StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("gb2312")))            {                sw.Write(htmlStr);            }                   }    }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.