The Service side is a paging class of text files. It is mainly processed in the stream. Of course, I have used the </BR> keyword on the Internet for paging.
I personally think that not all the time can meet the requirements. If I write this on myself, I still spend some time, mainly because I am too stupid and have a poor foundation. I hope you can give better suggestions.
CopyCode The Code is as follows: using system;
Using system. Collections. Generic;
Using system. text;
Using system. IO;
Namespace txt
{
Public class txtpager
{
Public txtpager ()
{}
Public txtpager (string _ txtpath, int _ pagesize)
{
{
This.txt Path = _ txtpath;
This. pagesize = _ pagesize;
}
}
String txtpath; // file path
Int pagesize; // number of lines per page
// Int PPT ;//
Int number;
// Int totalpage;
# Region
Public int totalpage
{
Get {
If (txtlinecount () % pagesize = 0)
Return txtlinecount ()/pagesize;
Else
Return txtlinecount ()/pagesize + 1 ;}
}
Public int PPT
{
Get {return txtlinecount ();}
}
Public int number
{
Get {return number ;}
Set {number = value ;}
}
# Endregion
Private int txtlinecount ()
{
Streamreader sr = new streamreader(this.txt path );
String line;
Int COUNT = 0;
While (line = Sr. Readline ())! = NULL)
{
// Line + = "fuck ";
Count ++;
}
Return count;
}
Public String readtxttohtml ()
{
String line; // stores a line of text
Int PTR = 0; // row count
Int TTP = 1; // the maximum number of pages after the page
Streamreader sr = new streamreader (txtpath );
String htmlstr = ""; // used to store HTML code
Htmlstr + = "#" + TTP + "</BR> ";
While (line = Sr. Readline ())! = NULL)
{
If (PTR = pagesize)
{
TTP ++;
Htmlstr + = "#" + TTP + "</BR> ";
TTP ++;
Htmlstr + = "#" + TTP + "</BR> ";
PTR = 0;
}
Htmlstr + = line + "</BR> ";
PTR ++;
}
Htmlstr + = "#" + (TTP + 1 );
// Return htmlstr;
If (number & gt; TTP + 1/2)
{
Number = TTP;
}
//.................................
String startstr = "#" + (2 * number-1); // 1
String endstr = "#" + (2 * number); // 2 1---2
Int startnum = htmlstr. indexof (startstr );
Int endnum = htmlstr. indexof (endstr );
Int offset = startstr. length;
Return htmlstr. substring (startnum + offset, endnum-(startnum + offset ));
}
}
}
Here is how to use this class:
This code is used to explain the usage of the paging class. It is not intuitive. It is mainly because when I write the code, I only need 6 paging files; you can also meet multiple requirements.
I am too lazy to write comments. I registered such a long blog Park to write so many bad things. It is far from your original intention. Copy code The Code is as follows: public partial class txtpager: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
Int pagesize = 40;
String _ Path = rtpath (Int. parse (request. querystring ["txtid"]);
String Path = httpcontext. Current. server. mappath (_ path );
TXT. txtpager TP = new TXT. txtpager (path, pagesize );
Int _ ttpage = TP. totalpage;
If (request. requesttype. tostring (). tolower () = "get ")
{
Response. Write (_ ttpage. tostring ());
Response. End ();
}
If (request. requesttype. tolower () = "Post ")
{
// String =
// The front end determines whether the index is a number.
String Index = request. querystring ["Index"];
TP. Number = int. parse (INDEX );
String context = TP. readtxttohtml ();
Response. Write (context );
Response. End ();
}
}
Private string rtpath (int I)
{
String [] pathcollection = {"test.txt", "tdays.txt", "problem.txt", "jion.txt", "serve.txt", "project.txt", "icexplain.txt "};
Return "TXT/" + pathcollection [I];
}
}
The above is also prepared for Ajax requests, but it is still rough to write. I hope the experts will not throw my eggs.
Ajax code Copy code The Code is as follows: <SCRIPT type = "text/JavaScript" Language = "JavaScript">
VaR XMLHTTP;
VaR pxmlhttp;
VaR totilpage;
VaR contectbody;
Function getxmlhttprequset ()
{
VaR rtxmlhttp;
Try
{Rtxmlhttp = new xmlhttprequset ();}
Catch (E)
{
Try
{
Rtxmlhttp = new activexobject ("mxxml2.xmlhttp ");
}
Catch (E)
{
Try {rtxmlhttp = new activexobject ("Microsoft. XMLHTTP ");}
Catch (E)
{Alert ("your browser does not support Ajax ");}
}
}
Return rtxmlhttp;
}
Function getpagercount ()
{
XMLHTTP = getxmlhttprequset ();
VaR url = "txtpager. aspx? Txtid = 0 ";
Try
{
XMLHTTP. Open ("get", URL, false );
}
Catch (E)
{Return false ;}
XMLHTTP. onreadystatechange = countcallback;
XMLHTTP. Send (null );
Return true;
}
Function countcallback ()
{
If (XMLHTTP. readystate = 4)
{
VaR COUNT = XMLHTTP. responsetext;
VaR I = 0;
For (I = 0; I <count; I ++)
{
VaR childdiv = Document. createelement ("Div ");
Document. getelementbyid ("count1"). appendchild (childdiv );
Childdiv. innerhtml = I + 1;
Childdiv. setattribute ("ID", I );
Childdiv. setattribute ("onclick", "gethtmlstring (" + (I + 1) + ")");
Gethtmlstring (1 );
}
}
}
Function gethtmlstring (I)
{
Pxmlhttp = getxmlhttprequset ();
VaR url = "txtpager. aspx? Txtid = 0 & Index = "+ I;
Pxmlhttp. Open ("Post", URL, false );
Pxmlhttp. onreadystatechange = contextpostback;
Pxmlhttp. Send (null );
}
Function contextpostback ()
{
If (pxmlhttp. readystate = 4)
{
VaR context = pxmlhttp. responsetext;
Document. getelementbyid ("article"). innerhtml = context;
}
}
</SCRIPT>
The code is easy to understand, because I will not write deep code. It is important for us to practice it. Cainiao are working hard. I will get a lot from this example.
At least when I was a novice cainiao, it would be very fast to see this example.
The following is the display part. This is a complete example. Be honest and be in chargeCopy codeThe Code is as follows: <Table width = "90%" border = "0" cellspacing = "0" cellpadding = "0">
<Tr>
<TD align = "center"> ice cream production methods </TD>
</Tr>
<Tr>
<TD id = "article" align = "Left" style = "font-size: 12px; Height: 805px"> TD>
</Tr>
<Tr>
<TD id = "count1" style = "height: auto; text-align: Right"> </TD>
</Tr>
</Table>
Finished !! I hope it will not disappoint people who come to view my code.