惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
SegmentFault 最新的问题
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - Franky
有赞技术团队
有赞技术团队
Last Week in AI
Last Week in AI
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
aimingoo的专栏
aimingoo的专栏
Recent Announcements
Recent Announcements
雷峰网
雷峰网
T
Tor Project blog
博客园_首页
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The Register - Security
The Register - Security
T
The Blog of Author Tim Ferriss
Recorded Future
Recorded Future
V
Vulnerabilities – Threatpost
Project Zero
Project Zero
J
Java Code Geeks
AWS News Blog
AWS News Blog
Security Latest
Security Latest
Spread Privacy
Spread Privacy
T
Threatpost
博客园 - 三生石上(FineUI控件)
I
Intezer
G
Google Developers Blog
Scott Helme
Scott Helme
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The Hacker News
The Hacker News
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
NISL@THU
NISL@THU
A
Arctic Wolf
F
Full Disclosure
P
Proofpoint News Feed
G
GRAHAM CLULEY
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
N
Netflix TechBlog - Medium
C
Cybersecurity and Infrastructure Security Agency CISA
T
Threat Research - Cisco Blogs
B
Blog
IT之家
IT之家
MongoDB | Blog
MongoDB | Blog
L
LangChain Blog
Know Your Adversary
Know Your Adversary

博客园 - 猫猫

SignalR 2.0 初次使用说明 解决VS2012上面EF字段说明备注没有的方法 生产百万级随机数 (转帖)C#批量重命名文件代码的实现 MyClipse DataBase Explorer 连接 ACCESS 配置说明 一个文本处理小工具(原创) C# 算法之 冒泡排序 实现数组转换为DataTable TreeView 部署到服务器上无法显示图标(失效) 仿google的suggest C# 把网页内容转为EXCEL,WORD C# 实现页面3秒后跳转 ASPNET动态生成静态页面 正则表达式30分钟入门教程 转 正则表达式之道 转 正则表达式基础知识 转 常用正则表式 转 转 正则表达式教程 正则表达式教程 (转)
C# 生产新闻文章分页
猫猫 · 2008-04-10 · via 博客园 - 猫猫

有的时候我们遇到输出的内容太长,导致失去页面美观。现在我们采用给这个内容分页的方法来解决此问题:
代码:

<div id="mycontent" runat="server" style="z-index: 101; left: 100px; width: 621px; position: absolute; top: 40px;
            height: 160px"
> </div>
            
<div id="pager" runat="server" align="center" style="z-index: 101; left: 1px; width: 618px; position: absolute; top: 162px;
                height: 34px"
>
            
</div>

前台页面两个DIV用来显示信息,mycontent用来显示新闻内容,pager 用来显示分页信息

protected void Page_Load(object sender, EventArgs e)
    
{
        
int page=1;//初始页面代码,一打开显示第一页内容
        string mypage;
        mypage 
= Request.QueryString["page"];
        
if (mypage != null//第一次的时候没有加载分页因此得到的结果为NULL,因此要判断一下
        {
            page 
= Convert.ToInt32(mypage);
        }


        
if (!Page.IsPostBack)
        
{
            
          
//string strsql = "select top 1 * from pageContent where title='chen1'";
            string content = "2008年4月9日(星期三)上午10时,国务院新闻办新闻发布厅举行新闻发布会,<P>请西藏自治区主席向巴平措、中共中央统战部副部长斯塔介绍近期西藏有关情况,并答记者问。<P>以下为发布会部分内容摘要。向巴平措:前一段时间,我在慰问无辜死亡人员的亲属、到医院去看望受伤人员,<P>与受到损害的商户座谈的时候一再表示,作为政府,作为自治区政府主席,没有能够对纳税人、对人民群众很好地加以保护,因此我表示深深的歉意,<P>而且明确表示,作为人民政府,对死亡人员,对受伤人员,政府会通过多种渠道妥善解决他们受到的损失和面临的困难问题。";
            
//以上内容可以从数据库中取得,这里为方便演示直接写上内容,用<P>来间隔要取得的内容
          
            
string[] strContent = null;
           
// SqlDataReader dr = cdb.mydr(strsql); 如果从数据库里读的话
           
// if (dr.Read())
           
// {
                strContent = filesplit(content);//调用filesplit方法取得数组形式的内容
           
// }
           
// dr.Close();
            if (strContent[page - 1!= null)
            
{
                
                
this.mycontent.InnerHtml = strContent[page - 1].ToString();//显示内容
            }

            
else
            
{
                
this.mycontent.InnerHtml = "无内容";

            }

            
string adpager = string.Empty;
            
for (int i = 0; i < strContent.Length; i++)
            
{  //循环数组取得内容分页数
                if (strContent[i] != null)
                
{
                   
int npage = i + 1;
                    
                   adpager
+="<a href=Default.aspx?page=" + npage + ">" + npage + "</a>";
                  
                   
                }

            }

            
this.pager.InnerHtml = adpager.ToString();//显示分页

        }



    }



    
public string[] filesplit(string contents)
    
{   
        
int fileindex = 0;
        
string[] splitfile = new string[10];
        
while (contents.Length > 10 && fileindex < 9)
        
{
            
if (contents.IndexOf("<P>"10< 0break;

            splitfile[fileindex] 
= contents.Substring(0, contents.IndexOf("<P>"10));//这里注意这里的10是字数,我是为了测试而采用10,你可以根据你的新闻页面再设置,我想最少也得200字吧。呵呵。。。。。。
            contents = contents.Remove(0, splitfile[fileindex].Length);
            fileindex
++;
        }

        splitfile[fileindex] 
= contents;
        
return splitfile;
    }

此文方法引荐自http://blog.csdn.net/chenguang79/archive/2008/03/28/2224977.aspx