HTML:
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "shownews. aspx. cs" inherits = "shownews" %>
<% @ Register src = "headcontrol. ascx" tagname = "headcontrol" tagprefix = "uc1" %>
<% @ Register src = "buttoncontrol. ascx" tagname = "buttoncontrol" tagprefix = "UC2" %>
<! 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 %> </title>
<Link href = "stylesheet.css" rel = "stylesheet" type = "text/CSS"/>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Table align = "center" border = "0" cellpadding = "0" cellspacing = "0" style = "width: 1000px">
<Tr>
<TD>
<Uc1: headcontrol id = "headcontrol1" runat = "server"/> </TD>
</Tr>
<Tr>
<TD class = "newslist">
Your current location & gt; <a href = "index. aspx" target = "_ Self"> homepage </a> & gt;
<Asp: hyperlink id = "hl_link"
Runat = "server"> [hyperlink1] </ASP: hyperlink> </TD>
</Tr>
<Tr> <TD>
<Table border = "0" cellpadding = "0" cellspacing = "0" style = "width: 100%">
<Tr>
<TD valign = "TOP" class = "newbakcolor">
<Table border = "0" cellpadding = "0" cellspacing = "0" style = "width: 100%">
<Tr>
<TD class = "newtitle">
<Asp: Label id = "lb_title" runat = "server"> </ASP: Label> </TD>
</Tr>
<Tr>
<TD align = "center" class = "newinfo">
<Asp: Label id = "lb_newinfo" runat = "server"> </ASP: Label> </TD>
</Tr>
<Tr>
<TD class = "newcontent">
<Div id = "newcontent" runat = "server">
& Nbsp; </div> </TD>
</Tr>
<Tr>
<TD class = "newcontent">
<Asp: panel id = "Panel1" runat = "server" visible = "false" width = "100%"> <strong> <Div id = "pageinfo" runat = "server" align = center> </div> </strong>
</ASP: Panel>
</TD>
</Tr>
</Table>
</TD>
& Lt; TD width = "300" align = "right" valign = "TOP" & gt;
<Table border = "0" cellpadding = "0" cellspacing = "0" class = "newtdcolor" style = "width: 98%">
<Tr>
<TD align = "Left" class = "newlistbg"> latest update </TD>
</Tr>
<Tr>
<TD align = left>
<Asp: datalist id = "datalist1" runat = "server" width = "100%">
<Itemtemplate>
<Table width = "100%" border = "0" cellspacing = "0" cellpadding = "0">
<Tr valign = "Middle">
<TD width = "7" Height = "24" align = "Left">
</TD>
<TD> <a href = 'shownews. aspx? Id = <% # databinder. eval (container. dataitem, "ns_id") %> 'title = '<% # databinder. eval (container. dataitem, "ns_subject") %> '> <% # databinder. eval (container. dataitem, "ns_subject") %> </a> </TD>
</Table>
</Itemtemplate>
</ASP: datalist> </TD>
</Tr>
</Table>
</TD>
</Tr>
</Table>
</TD> </tr>
<Tr>
<TD> <UC2: buttoncontrol id = "buttoncontrol1" runat = "server"/> </TD>
</Tr>
</Table>
</Div>
& Nbsp;
</Form>
</Body>
</Html>
C #:
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. Data. sqlclient;
Public partial class shownews: system. Web. UI. Page
{
Public String title;
Protected void page_load (Object sender, eventargs E)
{
Int page = 1; // initial PageCode . The first page is displayed.
String mypage;
Mypage = request. querystring ["page"];
If (mypage! = NULL) // when the page is not loaded for the first time, the result is null. Therefore, you need to determine
{
Page = convert. toint32 (mypage );
}
If (! Ispostback)
{
If (request. querystring ["ID"]! = NULL)
{
String ID, STR;
Id = request. querystring ["ID"]. Trim ();
STR = "Update News set ns_click = ns_click + 1 where ns_id =" + ID;
Db.exe cutesql (STR ,"");
STR = "select * from news where ns_id =" + ID;
Sqldatareader SDR = dB. getsdr (STR );
If (SDR. Read ())
{
// This. lb_content.text = SDR ["ns_content"]. tostring ();
This. lb_title.text = SDR ["ns_subject"]. tostring ();
Title = SDR ["ns_subject"]. tostring (). Trim () + "_" + SDR ["ns_type"]. tostring ();
This. hl_link.text = SDR ["ns_type"]. tostring ();
DB. binddatalist ("select Top 8 * from news where ns_type = '" + SDR ["ns_type"]. tostring (). trim () + "'order by ns_id DESC", this. datalist1, "ns_id ");
This. hl_link.navigateurl = "newslist. aspx? Type = "+ SDR [" ns_type "]. tostring (). Trim ();
This. lb_newinfo.text = "Author:" + SDR ["ns_author"]. tostring (). trim () + "clicks:" + SDR ["ns_click"]. tostring (). trim () + "updated at:" + SDR ["ns_date"]. tostring ();
// This. newcontent. innerhtml = "kfdfsdasddfdskjdfdkfjdfsj ";
// This. pageinfo. innerhtml = "kdkfjdkf ";
String content;
Content = SDR ["ns_content"]. tostring ();
String [] strcontent = NULL;
Strcontent = filesplit (content); // call the filesplit method to obtain the content in the array format
If (strcontent [page-1]! = NULL)
{
This. newcontent. innerhtml = strcontent [page-1]. tostring (); // display content
}
Else
{
This. newcontent. innerhtml = "NO content ";
}
String adpager = string. empty;
Int npage = 0;
For (INT I = 0; I <strcontent. length; I ++)
{// Obtain the number of pages in the cyclic Array
If (strcontent [I]! = NULL)
{
Npage = I + 1;
Adpager + = "<a href = shownews. aspx? Page = "+ npage +" & id = "+ request. querystring ["ID"]. trim () + ">" + "" + npage + "" + "</a> ";
}
}
If (npage> 1)
{
This. panel1.visible = true;
}
This. pageinfo. innerhtml = "paging information" + adpager. tostring (); // display the page
}
DB. closeall (null, null, SDR );
}
Else
{
DB. msgback ("parameter input error! "," Index. aspx ");
}
}
}
Public String [] filesplit (string contents)
{
Int fileindex = 0;
String [] splitfile = new string [10];
While (contents. length> 10 & fileindex <9)
{
String TT = @ "<Div style =" "Page-break-after: Always" "> <span style =" "display: none" "> & nbsp; </span> </div> ";
If (contents. indexof (TT, 10) <0) break;
Splitfile [fileindex] = contents. substring (0, contents. indexof (TT, 200); // note that 10 is the number of words here. I use 10 for testing. You can set it based on your news page, I guess it should contain at least 200 words. Haha ......
Contents = contents. Remove (0, splitfile [fileindex]. Length );
Fileindex ++;
}
Splitfile [fileindex] = contents;
Return splitfile;
}
}
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/wrzme/archive/2008/12/08/3475133.aspx