All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
用PHP实现Ftp用户的在线管理_php资料_编程技术
Asp.net中实现从弹出窗口中选择值_[Asp.Net教程]
asp.net回车键执行相应按钮事件的代码_[Asp.Net教程]
应用技巧:用PHP简易实现中文分词_php资料_编程技术
解决SqlTransaction用尽的问题(SQL处理超时)_[SQL,Server教程]
在网页中插入媒体播放器详细参考_[Html教程]
GDI+绘制柱型图分析商品月销售情况
PHP入门:在PHP关于变量的使用介绍_[PHP教程]
PHP学习:Smarty的分页实现_[PHP教程]
基础知识:PHP连接mysql测试和配置_php资料_编程技术
Reading number is top 10 pictures
西游四格漫画(一)
Chinese paper-cut grilles art appreciation3
看如何给单纯的少女洗脑
分手的感悟
生活中总有些低调的人,不经意间散发出土豪的气质
Group of female porn in 《westwards》, uninhibited woman threatened to not the bottom line
[猫扑大杂烩]华东师范墙上看到的捐精告示 15毫升3600元
Fierce! China's special forces training the devil2
移民小国也实惠1
The hot big eye big breast beauty1
Download software ranking
Tram sex maniac 2 (H) rar bag15
The cock of the Grosvenor LTD handsome
电车之狼R
Photoshop 8.0图象编辑软件
艳兽都市
卡丁车单机版
美女写真3
Eclipse 4.2.1 For Win32
Boxer Classic video3
Tram sex maniac 2 (H) rar bag10
归海一刀 published in(发表于) 2014/1/30 0:58:22 Edit(编辑)
asp.net2.0,动态生成静态页并分页实例_[Asp.Net教程]

asp.net2.0,动态生成静态页并分页实例_[Asp.Net教程]

asp.net2.0 动态生成静态页并分页实例_[Asp.Net教程]

 asp.net2.0 动态生成静态页并分页实例
看了看很多网页中的新闻都是分页的,我想实现这样的功能,看看他们实现的方法,基本是一个新闻分成多个html文件保存,然后用页码连接起来。(不知道我的理解是否正确,如果不正确请大家给我指点一二)
1、从数据库中获取新闻内容。包括新闻标题、内容等。
2、设置页面显示的字符串长度,获取新闻内容的字符长度。做初始设置
3、按页面大小设置的长度截取新闻内容的字符。
4、获取模板页面。在相关的替换字符中用标题、内容等替换字符串。
5、保存新页面到制定目录下面

下面是代码和资源管理器内容、

solid.aspx内容
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 System.IO;

public partial class solid : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
WriteFile("奥运专题", "奥运会真棒!
", "2", "2.html");
}
public void WriteFile(string strText, string content, string page, string name)
{
string path = HttpContext.Current.Server.MapPath("news/get");
System.Text.Encoding code = System.Text.Encoding.GetEncoding("gb2312");

// 读取模板文件
string temp = HttpContext.Current.Server.MapPath("news/text.htm");
StreamReader sr = null;
StreamWriter sw = null;
string str = "";
try
{
sr = new StreamReader(temp, code);
str = sr.ReadToEnd(); // 读取文件
}
catch (Exception exp)
{
HttpContext.Current.Response.Write(exp.Message);
HttpContext.Current.Response.End();
sr.Close();
}
string htmlfilename = name.ToString();
// 替换内容
// 这时,模板文件已经读入到名称为str的变量中了
str = str.Replace("title", strText); //模板页中的title,即标题
str = str.Replace("content", content);//模板页中的content,即内容
str = str.Replace("page", page);//模板页中的page,即页码连接格式

// 写文件
try
{
sw = new StreamWriter(path + "/" + htmlfilename, false, code);
sw.Write(str);
sw.Flush();
}
catch (Exception ex)
{
HttpContext.Current.Response.Write(ex.Message);
HttpContext.Current.Response.End();
}
finally
{
sw.Close();
}
}
}

text.htm内容



无标题页



文章分页测试


title


page


content








添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.