佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > asp.net+Ajax 文本文件靜態(tài)分頁(yè)實(shí)現(xiàn)代碼

asp.net+Ajax 文本文件靜態(tài)分頁(yè)實(shí)現(xiàn)代碼

熱門(mén)標(biāo)簽:電子圍欄 服務(wù)器配置 銀行業(yè)務(wù) 阿里云 科大訊飛語(yǔ)音識(shí)別系統(tǒng) Linux服務(wù)器 Mysql連接數(shù)設(shè)置 團(tuán)購(gòu)網(wǎng)站
服務(wù)端部分 ,文本文件分頁(yè)的類。主要在流中處理。當(dāng)然我看過(guò)網(wǎng)上的用/br> 關(guān)鍵字進(jìn)行分頁(yè)的
個(gè)人覺(jué)得不是所有時(shí)候都能滿足要求,所一自己寫(xiě)了這個(gè),還是費(fèi)了點(diǎn)時(shí)間,主要在于本人太笨,基礎(chǔ)很差。希望大家個(gè)出更好的建議
復(fù)制代碼 代碼如下:

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.txtPath = _txtPath;
this.pageSize = _Pagesize;
}
}
string txtPath;//文件路徑
int pageSize;//每頁(yè)文本行數(shù)
// 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.txtPath);
string line;
int count = 0;
while ((line = sr.ReadLine()) != null)
{
//line += "fuck";
count++;
}
return count;
}
public string ReadTxtToHtml()
{
string line;//存放一行文字
int ptr = 0;//行計(jì)數(shù)
int ttp = 1;//分頁(yè)后的最大頁(yè)數(shù)
StreamReader sr = new StreamReader(txtPath);
string htmlStr = "";//用于存放Html代碼
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 > 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));
}
}
}

這里是這個(gè)類的使用方法:
這段代碼用來(lái)解釋分頁(yè)類的使用有一點(diǎn)不直觀,主要是寫(xiě)的時(shí)候我是針對(duì)多的文件分頁(yè)的,還好我這里只需要6個(gè)而已;需要多個(gè)也可也滿足要求。
呵呵還沒(méi)有完善,注釋部分懶得寫(xiě),所以沒(méi)寫(xiě),哎是在是太懶了。注冊(cè)這么長(zhǎng)時(shí)間的博客園才寫(xiě)這么幾篇爛東西。跟自己的初衷還是想去甚遠(yuǎn)的。
復(fù)制代碼 代碼如下:

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 =
//前端判斷 index 是否為數(shù)字
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];
}
}

上面這也是為Ajax 的請(qǐng)求做準(zhǔn)備的,寫(xiě)的還是很粗糙的,希望高手莫扔我雞蛋
Ajax 代碼部分
復(fù)制代碼 代碼如下:

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("您的的瀏覽器不支持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 ; icount ; 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=0index="+ 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>

代碼還是很淺顯易懂的,呵呵因?yàn)槲乙膊粫?huì)寫(xiě)高深的代碼。重要的我們都要?jiǎng)邮秩?shí)踐。菜鳥(niǎo)們多多努力哦。做完我這個(gè)例子級(jí)會(huì)收獲很多哦。
至少當(dāng)我還是個(gè)初級(jí)菜鳥(niǎo)的時(shí)候要是有這個(gè)例子進(jìn)步會(huì)很快。
下面就是顯示的部分了。給大家一個(gè)完完整整的。做人要厚道要負(fù)責(zé)人
復(fù)制代碼 代碼如下:

table width="90%" border="0" cellspacing="0" cellpadding="0">
tr>
td align="center">冰激凌制作方法大全/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>

完成了??!希望會(huì)讓來(lái)看我代碼的人不會(huì)失望。
您可能感興趣的文章:
  • 簡(jiǎn)單好用的ASP.NET分頁(yè)類(支持AJAX、自定義文字)
  • asp.net使用AJAX實(shí)現(xiàn)無(wú)刷新分頁(yè)
  • asp.net中利用Jquery+Ajax+Json實(shí)現(xiàn)無(wú)刷新分頁(yè)的實(shí)例代碼
  • 用AJAX實(shí)現(xiàn)的無(wú)刷新的分頁(yè)實(shí)現(xiàn)代碼(asp.net)
  • AJAX分頁(yè)的代碼(后臺(tái)asp.net)
  • asp.net 使用ObjectDataSource控件在ASP.NET中實(shí)現(xiàn)Ajax真分頁(yè)
  • AspNetAjaxPager,Asp.Net通用無(wú)刷新Ajax分頁(yè)控件,支持多樣式多數(shù)據(jù)綁定
  • asp.net+ajax簡(jiǎn)單分頁(yè)實(shí)例分析

標(biāo)簽:萍鄉(xiāng) 蚌埠 江蘇 棗莊 衢州 衡水 廣元 大理

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp.net+Ajax 文本文件靜態(tài)分頁(yè)實(shí)現(xiàn)代碼》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    定远县| 康保县| 广州市| 大化| 霍林郭勒市| 吴川市| 阿瓦提县| 诸城市| 靖州| 马龙县| 石阡县| 通河县| 社旗县| 阿瓦提县| 垫江县| 炉霍县| 庐江县| 保定市| 泸定县| 禹州市| 松原市| 扬中市| 维西| 青冈县| 永宁县| 若尔盖县| 屯昌县| 方正县| 广汉市| 乌鲁木齐市| 南陵县| 永寿县| 都昌县| 临沧市| 太白县| 壶关县| 吴江市| 建平县| 邢台市| 固安县| 新郑市|