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

.net怎么实现内容分页显示

2012-01-11 
.net如何实现内容分页显示?.net如何实现内容分页显示[解决办法] %@ import Namespace System.Data.SqlC

.net如何实现内容分页显示?
.net如何实现内容分页显示

[解决办法]
<%@ import Namespace= "System.Data.SqlClient " %>
<script runat= "server ">

SqlConnection cn;
int textlen,prevlen,latelen;
string text;

void Page_Load(Object sender, EventArgs e) {
cn =new SqlConnection( "server=localhost;uid=sa;pwd=***;database=*** ");
SqlDataAdapter da = new SqlDataAdapter( "select text from test ",cn);
DataSet ds=new DataSet();
da.Fill(ds, "text ");
text=ds.Tables[ "text "].Rows[0][0].ToString();
textlen=text.Length;
prevlen=text.LastIndexOf( "p> ",14000)+2;
latelen=textlen-prevlen;
Label2.Text=text.Substring(0,prevlen);

}

void Button1_Click_1(object sender, EventArgs e) {
Label2.Text=text.Substring(prevlen,latelen);
}

void Button2_Click(object sender, EventArgs e) {
Label2.Text=text.Substring(0,prevlen);
}

</script>
<html>
<head>
</head>
<body topmargin= "0 ">
<form runat= "server ">
<table width= "550 " align= "center ">
<tbody>
<tr>
<td>
<asp:Label id= "Label2 " runat= "server "> Label </asp:Label> </td>
</tr>
<tr>
<td align= "middle ">
<asp:Button id= "Button1 " onclick= "Button1_Click_1 " runat= "server " Text= "下一页 "> </asp:Button>
<asp:Button id= "Button2 " onclick= "Button2_Click " runat= "server " Text= "上一页 "> </asp:Button>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
[解决办法]
建议使用分页存储过程
[解决办法]
datagrid 本身有自带的分页功能,代码也很简单
Datagrid:

Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
DataGrid1.CurrentPageIndex = e.NewPageIndex
BindDG()
End Sub

[解决办法]
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();
}

[解决办法]
插入标记符呀,然后换页
[解决办法]
这个也是我的一个难题哦,

我正考虑用标签,

呵呵! 楼主我帮你顶
[解决办法]
是啊!是内容分页啊.大家也不看清楚就回答了``!

------解决方案--------------------


加分页符号..
[解决办法]
添加信息的时候,就写入分页符,比如($);页面读取的时候,将内容切割放在数组中,就可以分开读取了.
如果要做好一点的,就后台添加新闻时生成静态页面的时候就分开,这样的话,读取速度快.

热点排行