.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)