public void CreateHTMLclass(string url, string viufile, int page, int maxpage, string filename)
{
StreamReader sr;
StreamWriter sw;
WebRequest HttpWebRequest = WebRequest.Create(url);
HttpWebRequest.Credentials = new NetworkCredential("administrator", "wenweifengijloqtd");
WebResponse HttpWebResponse = HttpWebRequest.GetResponse();
sr = new StreamReader(HttpWebResponse.GetResponseStream(), System.Text.Encoding.Default);
string strHtml = sr.ReadToEnd();
strHtml = strHtml.Replace("<!-- AspNetPager V5.0.1.0 for VS2005 Copyright:2003-2006 Webdiyer (http://www.webdiyer.com/) -->", "<!--分页程序开始-->").Replace("<!-- AspNetPager V5.0.1.0 for VS2005 End -->", "<!--分页程序结束-->");
int starint = strHtml.IndexOf("<!--分页程序开始-->");
string s = strHtml.Substring(starint, strHtml.Length - starint - 1);
int starend = s.IndexOf("<!--分页程序结束-->");
s = s.Substring(0, starend);
string pager = string.Empty;
if (page == 1)
{
//第一页的情况下分页链接
pager = "当前第<font color=#ff0000>" + page + "</font>页,共" + maxpage + "页 <a>第一页</a> <a>上一页</a> <a class=\"menulink\" href=\"" + System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Convert.ToString((page + 1 + page + 1)), "md5").Substring(2, 16).ToLower() + filename + "\">下一页</a> <a class=\"menulink\" href=\"" + System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Convert.ToString(maxpage + maxpage), "md5").Substring(2, 16).ToLower() + filename + "\">最后一页</a>";
}
else if (page > 1 && page < maxpage)
{
pager = "当前第<font color=#ff0000>" + page + "</font>页,共" + maxpage + "页 <a class=\"menulink\" href=\"" + (System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Convert.ToString((1 + 1)), "md5")).Substring(2, 16).ToLower() + filename + "\">第一页</a> <a class=\"menulink\" href=\"" + (System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Convert.ToString((page - 1) + (page - 1)), "md5")).Substring(2, 16).ToLower() + filename + "\">上一页</a> <a class=\"menulink\" href=\"" + (System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Convert.ToString((page + 1) + (page + 1)), "md5")).Substring(2, 16).ToLower() + filename + "\">下一页</a> <a class=\"menulink\" href=\"" + (System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Convert.ToString((maxpage) + (maxpage)), "md5")).Substring(2, 16).ToLower() + filename + "\">最后一页</a>";
}
else if (page == maxpage)
{
//最后页的情况下分页链接
pager = "当前第<font color=#ff0000>" + page + "</font>页,共" + maxpage + "页 <a class=\"menulink\" href=\"" + (System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Convert.ToString((1) + (1)), "md5")).Substring(2, 16).ToLower() + filename + "\">第一页</a> <a class=\"menulink\" href=\"" + (System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Convert.ToString((page - 1) + (page - 1)), "md5")).Substring(2, 16).ToLower() + filename + "\">上一页</a> <a>下一页</a> <a>最后一页</a>";
}
pager = pager + " 跳转到:<select name=\"jumppage\" onchange=\"if(this.options[this.selectedIndex].value != '') {window.location=(this.options[this.selectedIndex].value);}\">";
for (int k = 1; k <= maxpage; k++)
{
if (k == page)
pager = pager + "<option value=" + (System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Convert.ToString((k) + (k)), "md5")).Substring(2, 16).ToLower() + filename + " selected>第" + k + "页</option>";
else
pager = pager + "<option value=" + (System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Convert.ToString((k) + (k)), "md5")).Substring(2, 16).ToLower() + filename + ">第" + k + "页</option>";
}
pager = pager + "</select>";
strHtml = strHtml.Replace(s, pager);
sw = File.CreateText(HttpContext.Current.Server.MapPath("~/" + viufile));
sw.WriteLine(strHtml);
sw.Close();
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/taokai/archive/2008/01/02/2009559.aspx