做一个新闻系统,为了让他比较完美,需要在显示详细新闻内容的地方增加如下功能,  如果一条新闻的字符过多则需要分页显示!   
那个大哥有相关代码      麻烦给一个    或者给个思路!  谢了?

解决方案 »

  1.   

    我认为代码分也是不可能实现的,或者是非常难的。
    好考虑的东西很多,单词不能拆开吧, li_new() 说的地方,还有如果带有html标记的话就更麻烦了
    html标记不能拆吧,<table>要是被拆开了,会是什么样子呀?成对的标记也不能拆开有了<table>
    而没有</table>也是会乱的。还有哇,如果带图片的话,你怎么计算高度呀,几幅图片分一页呀。好多问题呢,如果你真能实现的话,那你可就是高手高手高高手了。好了,不说废话了。我的办法是,添新闻的时候手动分页。也就是说让编辑在添加新闻的时候自己判断是单页的还是多页的,当然了要自己写一个程序来实现这个功能了。总结:不要研究怎么用代码来对已经填好的新闻进行分页了,转到研究在添新闻的时候,提供一个能够加多页新闻的方法,让编辑在添新闻的时候自己来分页吧。我的新闻系统就是这么做的。http://news.sanhaoonline.com  有兴趣的话可以参看一下。
      

  2.   

    用ASP.NET和XML做的新闻系统 介绍这几个文件。 
    contents.xml 
    <?xml version="1.0" encoding="GB2312"?> 
    <topiclist type="AspCool News"> 
    <topic> 
    <title>aspcool news!</title> 
    <href>main.aspx?name=hello</href> 
    </topic> 
    <topic> 
    <title>Resolve a problem</title> 
    <href>main.aspx?name=test</href> 
    </topic> 
    </topiclist> 
    这是一个很简单的xml文件,它的作用是用来显示新闻的列表。 
    hello.xml 
    <?xml version="1.0" encoding="GB2312"?> 
    <document> 
    <title>aspcool news!</title> 
    <abstract>test news</abstract> 
    <author>feiying</author> 
    <content> 
    <paragraph>The firet test</paragraph> 
    </content> 
    </document> 
    这个文件是用来显示新闻的内容,其中各个意思大家一看就明白,我就不在这儿多说了。
    下面给大家看新闻列表显示的页面。 
    news.aspx 
    <%@ Import Namespace="System"%> 
    <%@ Page Language="C#" Debug="true" codepage="936"%> 
    <%@ Import Namespace="System.IO" %> 
    <%@ Assembly Name="System.Xml" %> 
    <%@ Import Namespace="System.Xml" %> 
    <%@ Import Namespace="System.Xml.Xsl" %> 
    <html> 
    <head> 
    <title> 
    </title> 
    <script language="c#" runat="server"> 
    public string xslt() 

     StringWriter writer = new StringWriter(); 
     //装入xml对象 
     XmlDocument xmldoc= new XmlDocument(); 
     xmldoc.Load(Server.MapPath("Contents.xml")); 
     //装入xsl对象 
     XslTransform xsldoc = new XslTransform(); 
     xsldoc.Load(Server.MapPath("news.xsl")); 
     //把xml转化成html页面 
     DocumentNavigator nav= new DocumentNavigator(xmldoc); 
     xsldoc.Transform(nav,null,writer); 
     return writer.ToString(); 

    </script> 
    </head> 
    <body> 
    <%=xslt()%> 
    <p align="center">
    该程序由<a href="www.aspcool.comhttp://www.aspcool.com">www.aspcool.com</a>设计制作.
    </p> 
    </body> 
    </html> 
    这个页面完成了从xml通过xslt转化成html文件,也使我对于xslt有了进一步的认识。 
    下面是新闻内容显示的页面: 
    main.aspx 
    <%@ Import Namespace="System"%> 
    <%@ Page Language="C#" Debug="true" codepage="936"%> 
    <%@ Import Namespace="System.IO" %> 
    <%@ Assembly Name="System.Xml" %> 
    <%@ Import Namespace="System.Xml" %> 
    <%@ Import Namespace="System.Xml.Xsl" %> 
    <html> 
    <head> 
    <title> 
    </title> 
    <script language="c#" runat="server"> 
    public string xslt() 

     StringWriter writer = new StringWriter(); 
     XmlDocument xmldoc= new XmlDocument(); 
     xmldoc.Load(Server.MapPath(Request["name"] +".xml")); 
     XslTransform xsldoc = new XslTransform(); 
     xsldoc.Load(Server.MapPath("main.xsl")); 
     DocumentNavigator nav= new DocumentNavigator(xmldoc); 
     xsldoc.Transform(nav,null,writer); 
     return writer.ToString(); 

    </script> 
    </head> 
    <body> 
    <%=xslt()%> 
    <p align="center">该程序由<a href="www.aspcool.comhttp://www.aspcool.com">www.aspcool.com</a>设计制作.</p> 
    </body> 
    </html> 
    这个功能和上面的一样,我在这儿就不多说了。 最后,大家来看一下最负责的一个页面,这个页面的作用就是用来建立新的xml数据。 
    manage.aspx 
    <%@ Import Namespace="System.Xml.Xsl" %> 
    <%@ Import Namespace="System.Xml" %> 
    <%@ Assembly Name="System.Xml" %> 
    <%@ Import Namespace="System.IO" %> 
    <%@ Page Language="C#" Debug="true" codepage="936"%> 
    <%@ Import Namespace="System"%> 
    <HTML> 
    <HEAD> 
    <script language="C#" runat="server"> 
    public void Button1_Click(object sender, System.EventArgs e) 

     //判断文件是否存在 
     if(File.Exists(Server.MapPath(TextBox1.Text +".xml"))) 
     { 
      Response.Write("文件名已经存在,请重选文件名。"); 
      Response.End() ;  
     } 
     else 
     { 
      XmlNode currNode; 
      XmlDocument xmldoc = new XmlDocument(); 
      xmldoc.Load(Server.MapPath("contents.xml")); 
      string InsStr="<topic><title>"+TextBox2.Text+"</title><href>
       main.aspx?name="+TextBox1.Text+"</href></topic>"; 
      XmlDocumentFragment docFrag = xmldoc.CreateDocumentFragment(); 
      docFrag.InnerXml = InsStr; 
      currNode = xmldoc.DocumentElement; 
      currNode.InsertAfter(docFrag, currNode.LastChild); 
      //save the output to a file 
      xmldoc.Save (Server.MapPath("contents.xml")); 
      //把TextBox5中的文件换成符合xml格式的内容。 
      string xmlfile =TextBox5.Text.Replace("&","&"); 
      xmlfile = xmlfile.Replace("<","<"); 
      xmlfile = xmlfile.Replace(">",">"); 
      xmlfile = xmlfile.Replace( @"""""","""); 
      xmlfile = xmlfile.Replace(""","&apos;"); 
      xmlfile = xmlfile.Replace ("\n","</paragraph><paragraph>"); 
      //把数据写入新建的xml文件中去。 
      XmlDocument doc = new XmlDocument(); 
      doc.LoadXml ("<?xml version="1.0" encoding="GB2312"?>
       <document><title>"+TextBox2.Text +"</title><abstract>"+
       TextBox4.Text "</abstract><author>"+TextBox3.Text+
       "</author><content><paragraph>"+xmlfile+"</paragraph>
       </content></document>"); 
      doc.Save (Server.MapPath(TextBox1.Text +".xml")); 
      Response.Write("You hava input the article!"); 
      TextBox1.Text=""; 
      TextBox2.Text=""; 
      TextBox3.Text=""; 
      TextBox4.Text=""; 
      TextBox5.Text=""; 
     } 
     //向目录文件中写数据 

    public void Button2_Click(object sender, System.EventArgs e) 
    {} 
    </script> 
    <meta content="Internet Explorer 5.0" name=vs_targetSchema> 
    <meta content="Microsoft Visual Studio 7.0" name=GENERATOR> 
    <meta content=C# name=CODE_LANGUAGE> 
    </HEAD> 
    <body MS_POSITIONING="GridLayout"> 
    <form runat="server"> 
    <FONT face=宋体> 
    <asp:label id=Label1 style="Z-INDEX: 100; LEFT: 230px; POSITION:
     absolute; TOP: 27px" runat="server" Height="28px" Width="156px"> 
    asp酷技术资讯网网站内容发布系统 
    </asp:label> 
    <asp:label id=Label2 style="Z-INDEX: 101; LEFT: 110px; POSITION: 
    absolute; TOP: 68px" runat="server" Height="25px" Width="65px"> 
    文件名: 
    </asp:label> 
    <asp:textbox id=TextBox1 style="Z-INDEX: 102; LEFT: 255px; POSITION: 
    absolute; TOP: 64px" runat="server" Height="33px" Width="178px" > 
    </asp:textbox> 
    <asp:label id=Label3 style="Z-INDEX: 103; LEFT: 108px; POSITION: 
    absolute; TOP: 126px" runat="server" Height="36px" Width="86px"> 
    文章名称: 
    </asp:label> 
    <asp:textbox id=TextBox2 style="Z-INDEX: 104; LEFT: 256px; POSITION: 
    absolute; TOP: 114px" runat="server" Height="37px" Width="177px"> 
    </asp:textbox> 
    <asp:label id=Label4 style="Z-INDEX: 105; LEFT: 114px; POSITION: 
    absolute; TOP: 183px" runat="server" Height="31px" Width="89px"> 
    作者: 
    </asp:label> 
    <asp:textbox id=TextBox3 style="Z-INDEX: 106; LEFT: 256px; POSITION: 
    absolute; TOP: 183px" runat="server" Height="36px" Width="179px"> 
    </asp:textbox> 
    <asp:label id=Label5 style="Z-INDEX: 107; LEFT: 114px; POSITION: 
    absolute; TOP: 241px" runat="server" Height="51px" Width="81px"> 
    摘要: 
    </asp:label> 
    <asp:textbox id=TextBox4 style="Z-INDEX: 108; LEFT: 256px; POSITION: 
    absolute; TOP: 245px" runat="server" Height="36px" Width="179px"> 
    </asp:textbox> 
    <asp:label id=Label6 style="Z-INDEX: 109; LEFT: 116px; POSITION: 
    absolute; TOP: 315px" runat="server" Height="36px" Width="78px"> 
    内容: 
    </asp:label> 
    <asp:textbox id=TextBox5 style="Z-INDEX: 110; LEFT: 259px; POSITION: 
    absolute; TOP: 303px" runat="server" Height="95px" Width="252px" 
    textmode="MultiLine"> 
    </asp:textbox> 
    </FONT> <INPUT id=Button2 style="Z-INDEX: 113; LEFT: 343px; WIDTH: 40px; 
    POSITION: absolute; TOP: 430px; HEIGHT: 24px" type=button value=重置 
    name=Button2 runat="server" OnServerClick="Button2_Click" DESIGNTIMEDRAGDROP="59"> 
    <br> 
    <br> 
    <div id=mess runat=server> 
    </div> 
    <br> 
    <input type="button" value="提交" OnServerClick="Button1_Click" 
    runat="server" ID="Button1" NAME="Button1" style="Z-INDEX: 112;
     LEFT: 268px; POSITION: absolute; TOP: 430px"> 
    </form> 
    </body> 
    </HTML> 
      

  3.   

    我的方法是自己定义分页的位置,这样也很美观的
       Public Function textsplit(ByVal newstext As String, ByVal pageid As Integer, ByVal newsid As Integer)
                Dim sumpage As Integer
                Dim str As String
                Dim strarry As String()
                '返回内容主体
                strarry = newstext.Split("\")
                sumpage = strarry.Length
                str = strarry(pageid - 1)
                '先判断是否需要分页
                '如果只有1页时不需要分页
                If sumpage = 1 Then            Else
                    '如果不是首页提供上页连接
                    If pageid = 1 Then
                        str += "<br><a href='View.aspx?Id=" & newsid & "&Page=" & pageid + 1 & "'>下页</a>"
                    End If
                    '首页和尾页之间
                    If pageid > 1 And pageid < sumpage Then
                        str += "<br><a href='View.aspx?Id=" & newsid & "&Page=" & pageid - 1 & "'>上页</a>"
                        str += "<a href='View.aspx?Id=" & newsid & "&Page=" & pageid + 1 & "'>下页</a>"
                    End If
                    '尾页
                    If pageid = sumpage Then
                        str += "<br><a href='View.aspx?Id=" & newsid & "&Page=" & pageid - 1 & "'>上页</a>"
                    End If
                End If
                Return str
            End Function