<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        Asp.NET 生成靜態頁面并分頁的代碼

        來源:懂視網 責編:小采 時間:2020-11-27 22:43:21
        文檔

        Asp.NET 生成靜態頁面并分頁的代碼

        Asp.NET 生成靜態頁面并分頁的代碼:1、靜態模板頁面 template.html,主要是定義了一些特殊字符,用來被替換。 代碼如下:<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//ENhttp://www.w3.org/TR/html4/loose.dtd> <htm
        推薦度:
        導讀Asp.NET 生成靜態頁面并分頁的代碼:1、靜態模板頁面 template.html,主要是定義了一些特殊字符,用來被替換。 代碼如下:<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//ENhttp://www.w3.org/TR/html4/loose.dtd> <htm

        1、靜態模板頁面 template.html,主要是定義了一些特殊字符,用來被替換。
        代碼如下:

        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
        <html>
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
        <title>Title </title>
        </head>
        <body>
        <div style="width: 417px; height: px" 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 >查看更多評論 </a> </form>
        </div>
        </body>
        </html>

        2、前態頁面 NewsAdd.aspx,就是一個表單,用來填寫新聞的標題和內容。
        代碼如下:

        <%@ Page Language="C#" AutoEventWireup="false" validateRequest="false" CodeFile="NewsAdd.aspx.cs" Inherits="NewsAdd.Admin_AdminPanel_NewsAdd" %>
        <%@ Register TagPrefix="FCKeditorV2" Namespace="FredCK.FCKeditorV2" Assembly="FredCK.FCKeditorV2" %>
        <!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 runat="server">
        <title>添加新聞 </title>
        </head>
        <body>
        <form id="form1" runat="server">
        <div>
        <asp:Label ID="Label2" runat="server" Text="標題"> </asp:Label>
        <asp:TextBox ID="Title" runat="server" Width="325px"> </asp:TextBox> <br />
        <asp:Label ID="Label1" runat="server" Text="內容"> </asp:Label>
        <FCKeditorV2:FCKeditor id="Content" basePath="~/FCKeditor/" runat="server" Height="400px" Width="70%"> </FCKeditorV2:FCKeditor>
        <asp:Button ID="Button1" runat="server" onClick="Button1_Click" Text="Button" />
        <asp:Label ID="Message" runat="server" > </asp:Label> </div>
        </form>
        </body>
        </html>

        3、后臺頁面 NewsAdd.aspx.cs
        代碼如下:

        using System;
        using System.Data;
        using System.Configuration;
        using System.Collections;
        using System.Web;
        using System.Web.Security;
        using System.Web.UI;
        using System.Web.UI.WebControls;
        using System.Web.UI.WebControls.WebParts;
        using System.Web.UI.HtmlControls;
        using Mysqlserver;
        using System.IO;
        using System.Text;
        namespace NewsAdd
        {
        public partial class Admin_AdminPanel_NewsAdd : System.Web.UI.Page
        {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
        string strDate = DateTime.Now.ToString("yyMMdd") + "" + DateTime.Now.ToString("yyyymmddhhmmss");
        string strFileName = strDate + ".shtml";//存儲到數據庫中 stockbests.cn
        string strTitle=Request.Form["Title"].ToString().Trim();//接收傳過來的標題
        string strContent=Request.Form["Content"].ToString().Trim();//接收傳過來的內容
        string[] content = strContent.Split(new Char[] );//對內容進行拆分,并保存到數組
        int upbound = content.Length;//數組的上限
        SqlServerDataBase db = new SqlServerDataBase();
        bool success = db.Insert("insert into inNews(Title,Content,FilePath)values('" + strTitle + "','" + strContent + "','" + strFileName + "')", null);
        //if (success)
        // Message.Text = "添加成功!"; stockbests.cn
        /**////////////////////////////創建當前日期的文件夾開始
        string dir = Server.MapPath("http://www.cnblogs.com/"+"NewsFiles/"+DateTime.Now.ToString("yyMMdd"));//用來生成文件夾
        if (!Directory.Exists(dir))
        {
        Directory.CreateDirectory(dir);
        }
        /**////////////////////////////創建當前日期的文件夾結束
        try
        {
        for (int i = 0; i < content.Length; i++)
        {
        //string[] newContent = new string[4];//定義和html標記數目一致的數組
        StringBuilder strhtml = new StringBuilder();
        //創建StreamReader對象
        using (StreamReader sr = new StreamReader(Server.MapPath("http://www.cnblogs.com/" + "NewsFiles/") + "template.html",Encoding.GetEncoding("gb2312")))
        {
        String oneline;
        //讀取指定的HTML文件模板
        while ((oneline = sr.ReadLine()) != null)
        {
        strhtml.Append(oneline);
        }
        sr.Close();
        }
        //為標記數組賦值
        //SqlServerDataBase db = new SqlServerDataBase();
        DataSet ds = db.Select("select top 1 NewsId from inNews order by NewsId desc", null);//獲取id
        string strTable = " <table> <tr> <td>upUrl </td> <td>Number </td> <td>downUrl </td> </tr> </table>";//上下頁表格,注意此處的upUrl(上一頁),Number(頁碼分頁),downUrl(下一頁)
        //這三個是用來替換的。
        string FilePath="";
        strhtml = strhtml.Replace("Title", strTitle);
        strhtml = strhtml.Replace("NewsId", ds.Tables[0].Rows[0]["NewsId"].ToString());
        strhtml = strhtml.Replace("Time", DateTime.Now.ToString("yyyy/MM/dd"));
        strhtml = strhtml.Replace("Content", content[i]);
        string strNumber = "";//數字分頁1,2,3……
        for (int m = 1; m <=upbound; m++)
        {
        if (m == 1)//如果是第一頁就顯示成這個樣子:20070524.shtml而不是20070524_1.shtml
        strNumber = strNumber + " ["+" <a href=" + "../" + strDate + ".shtml" + ">" + m + " </a>"+"] ";
        else
        {
        int n = m - 1;//第三頁的連接應該是20070524_2.shtml,以此類推
        strNumber = strNumber + " [" +" <a href=" + "../" + strDate + "_" + n + ".shtml" + ">" + m + " </a>"+"] ";
        }
        }
        if (upbound == 0)//如果沒有分頁,就直接按日期時間保存
        {
        FilePath = Server.MapPath("http://www.cnblogs.com/") + "NewsFiles" + "http://" + strDate + ".shtml";
        strhtml = strhtml.Replace("Pager", "");
        }
        else//否則按20070524.shtml、20070524_1.shtml 這種效果保存
        {
        if (i == 0)
        FilePath = Server.MapPath("http://www.cnblogs.com/") + "NewsFiles" + "http://" + strDate + ".shtml";
        else
        FilePath = Server.MapPath("http://www.cnblogs.com/") + "NewsFiles" + "http://" + strDate + "_" + i + ".shtml";
        if (i == 0)//第一頁不顯示上一頁
        strTable = strTable.Replace("upUrl", "");
        if (i <= 1)//上一頁分頁
        strTable = strTable.Replace("upUrl", " <a href=" + "../" + strDate + ".shtml" + ">上一頁 </a>");
        else
        {
        int p = i - 1;
        strTable = strTable.Replace("upUrl", " <a href=" + "../" + strDate + "_" + p + ".shtml" + ">上一頁 </a>");
        }
        if(upbound==1)//如果只有一頁,則不顯示頁碼
        //strNumber="";
        strTable = strTable.Replace("Number", "");
        else
        strTable = strTable.Replace("Number", strNumber);//頁碼替換
        /**/////////////////////////
        if(i==upbound-1)//最后一頁不顯示下一頁
        strTable = strTable.Replace("downUrl", "");
        if (i != upbound - 1)//下一頁分頁
        {
        int q = i + 1;
        strTable = strTable.Replace("downUrl", " <a href=" + "../" + strDate + "_" + q + ".shtml" + ">下一頁 </a>");
        }
        else
        {
        int j = upbound - 1;
        strTable = strTable.Replace("downUrl", " <a href=" + "../" + strDate + "_" + j + ".shtml" + ">下一頁 </a>");
        }
        strhtml = strhtml.Replace("Pager", strTable);
        }
        //創建文件信息對象--------------------------------------------
        FileInfo finfo = new FileInfo(FilePath);
        //以打開或者寫入的形式創建文件流
        using (FileStream fs = finfo.OpenWrite())
        {
        //根據上面創建的文件流創建寫數據流
        StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Default);
        //把新的內容寫到創建的HTML頁面中
        sw.WriteLine(strhtml);
        sw.Flush();
        sw.Close();
        }
        }
        }
        catch (Exception err)
        {
        //
        輸出異常信息
        Response.Write(err.ToString());
        }
        }
        }
        }

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        Asp.NET 生成靜態頁面并分頁的代碼

        Asp.NET 生成靜態頁面并分頁的代碼:1、靜態模板頁面 template.html,主要是定義了一些特殊字符,用來被替換。 代碼如下:<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//ENhttp://www.w3.org/TR/html4/loose.dtd> <htm
        推薦度:
        標簽: html net 分頁
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 2020因为爱你带字幕免费观看全集| 一级午夜免费视频| 91精品免费观看| 亚洲AV无码乱码国产麻豆穿越| 一级免费黄色大片| 狠狠亚洲婷婷综合色香五月排名| 免费视频精品一区二区| 亚洲国产精品自产在线播放 | 国产成人无码区免费A∨视频网站| 青青草97国产精品免费观看| 免费高清资源黄网站在线观看| 亚洲最大av资源站无码av网址| 扒开双腿猛进入爽爽免费视频| 亚洲av成人中文无码专区| 国产大片线上免费看| 曰批免费视频播放免费| 久久国产成人亚洲精品影院| 国产做国产爱免费视频| 女人18毛片a级毛片免费| 亚洲av无码成人精品区一本二本| 免费一级e一片在线播放| 一区二区三区免费看| 亚洲AV第一页国产精品| 麻豆视频免费观看| 久久久亚洲精华液精华液精华液 | 亚洲精品无码你懂的网站| 最近更新免费中文字幕大全| 77777_亚洲午夜久久多人| 人妻18毛片a级毛片免费看| 情人伊人久久综合亚洲| 老外毛片免费视频播放| 亚洲精品成人片在线播放| 免费观看无遮挡www的视频| 色窝窝亚洲AV网在线观看| 久久久久久A亚洲欧洲AV冫| 6080午夜一级毛片免费看6080夜福利 | 人人公开免费超级碰碰碰视频| 亚洲av午夜福利精品一区 | 两个人看的www免费视频| 亚洲国产日韩在线| 亚洲av中文无码|