如何用asp.net2.0 c# 实现新闻分页,每个分页都生成html文件
解决方案 »
- radio与数据库绑定的问题
- asp.net中怎么处理并发操作
- 系统中装了IE9和Firefox SuperPreview 中却只有IE6
- HTML的数据 转成 JSON数据中的 因HTML有大量"及其它特殊符号会把JSON字符串截断该怎么处理
- 请教如何在.net中的客户端设置定时提交服务器
- 添加右键菜单的问题
- 怎样用语句截去每级单位(传入的单位编码是不知道的)后面的0 ?
- [紧急求助] .net 操作word出现问题,程序没有反应,也没有出现错误,代码如下
- 怎么取得从一个页面提交来的数据来着?好像用request,又不知道确切的用法
- 如何使显示出来的文本格式与在textarea中输入的格式一样??
- 一个SQL查询时间段的问题
- 本人做了一个新网站,全英文,希望大家支持一下,谢谢
参考
http://www.cnblogs.com/supers/articles/1276387.html
若没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();
}
}
public string getPageNav(int iCurrentPage, int iPageCount, string Http)
{
string OutStr = ""; if (iCurrentPage == 1)
{
OutStr += " <font color=\"#666666\">[首页]</font> <font color=\"#666666\">[上一页]</font>";
}
else
{
OutStr += " <a href='" + Http + "1.Htm'><font color=\"#800000\">[首页]</font></a>";
OutStr += " <a href='" + Http + (iCurrentPage - 1) + ".Htm'><font color=\"#800000\">[上一页]</font></a>";
}
OutStr += " "; if (iCurrentPage < iPageCount)
{
OutStr += "<a href='" + Http + (iCurrentPage + 1) + ".Htm'><font color=\"#800000\">[下一页]</font></a>";
OutStr += " <a href='" + Http + iPageCount + ".Htm'><font color=\"#800000\">[尾页]</font></a>";
}
else
{
OutStr += "<font color=\"#666666\">[下一页]</font> <font color=\"#666666\">[尾页]</font>";
} OutStr += " " + iCurrentPage + "/" + iPageCount + " ";
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()'> ";
return OutStr;
}
//分页函数《结束》
这个sql语句就是读出第一页之后的数据
分页判断正文字数 和生产多少页