首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

关于分页生成html?解决办法

2012-01-19 
关于分页生成html??????新闻列表比如news.aspx?page1,news.aspx?page2,news.aspx?page3不考虑用重写。。。

关于分页生成html??????
新闻列表比如news.aspx?page=1,news.aspx?page=2,news.aspx?page=3
不考虑用重写。。。。
怎么用代码来实现生成new_1.html,new_2.html,new_3.html
很急!在此求教!


[解决办法]
private void PageDisplay()
{
SqlConnection conn = new SqlConnection();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter sda = new SqlDataAdapter();
DataSet ds = new DataSet();
DataTable dt = new DataTable();

conn.ConnectionString = "server=.;pwd=sa;uid=sa;database=Northwind ";
cmd.Connection = conn;
cmd.CommandText = "select OrderId,EmployeeID,OrderDate,RequiredDate,ShippedDate from orders ";
sda.SelectCommand = cmd;
sda.Fill(ds, "Em ");
dt = ds.Tables[0];


nRecCount = dt.Rows.Count;
StringBuilder sb = new StringBuilder( " ");

if(nRecCount > 0)
{
PageCount = nRecCount / 10;
if(nRecCount / 10 > 0)
{
PageCount++;
}
if(this.Request.QueryString[ "page "] == null)
{
nPage = 1;
}
else
{

this.nPage = int.Parse(this.Request.QueryString[ "page "]);

}if(this.nPage < 1)
{
nPage = 1;
}
if(this.nPage > this.PageCount)
{
this.nPage = this.PageCount;
}

if(nPage == 1)
{
sb.Append( " <a href= 'WebForm1.aspx?page=1 '> 首页 </a> ")
.Append( " <a href= 'WebForm1.aspx?page= ")
.Append(nPage + 1)
.Append( " '> 下一页 </a> ")
.Append( " <a href= 'WebForm1.aspx?page= ")
.Append(PageCount)
.Append( " '> 尾页 </a> ")
.Append( "&nbsp;&nbsp;&nbsp;&nbsp;页次: ")
.Append(nPage.ToString())
.Append( "/ ")
.Append(PageCount.ToString())
.Append( " <br> ");
}
else
if(nPage == PageCount)
{
sb.Append( " <a href= 'WebForm1.aspx?page=1 '> 首页 </a> ")
.Append( " <a href= 'WebForm1.aspx?page= ")
.Append(nPage - 1)
.Append( " '> 上一页 </a> ")
.Append( " <a href= 'WebForm1.aspx?page= ")
.Append(PageCount)
.Append( " '> 尾页 </a> ")
.Append( "&nbsp;&nbsp;&nbsp;&nbsp;页次: ")
.Append(nPage.ToString())
.Append( "/ ")
.Append(PageCount.ToString())
.Append( " <br> ");
}
else
{
sb.Append( " <a href= 'WebForm1.aspx?page=1 '> 首页 </a> ")
.Append( " <a href= 'WebForm1.aspx?page= ")
.Append(nPage - 1)
.Append( " '> 上一页 </a> ")
.Append( " <a href= 'WebForm1.aspx?page= ")
.Append(nPage + 1)
.Append( " '> 下一页 </a> ")
.Append( " <a href= 'WebForm1.aspx?page= ")
.Append(PageCount)
.Append( " '> 尾页 </a> ")
.Append( "&nbsp;&nbsp;&nbsp;&nbsp;页次: ")
.Append(nPage.ToString())
.Append( "/ ")
.Append(PageCount.ToString())
.Append( " <br> ");
}
this.Response.Write(sb);


int Start = 10 * (nPage -1);
int End = Start + 10 -1;
if(End > nRecCount -1 )
{
End = nRecCount -1;
}
this.Response.Write( " <table border = '1 ' cellpadding = '0 ' cellspaceing = '0 ' style = 'bordercollapse:collapse 'bordercolor = '#111111 ' bgcolor = '#ffffff '> <tr> ");
this.Response.Write( " <td> OrderId </td> <td> EmployeeID </td> <td> OrderDate </td> <td> RequireDate </td> <td> ShippedDate </td> </tr> ");

sb.Remove(0,sb.Length);

for(int i = Start; i <= End; i++)
{
sb.Append( " <tr> ");
for(int j = 0;j < 5;j++)
{
sb.Append( " <td> " + dt.Rows[i][j].ToString() + " </td> ");
}
sb.Append( " </tr> ");
}
sb.Append( " </table> ");
this.Response.Write(sb);
}
conn.Close();
}
[解决办法]
记得给分

热点排行