using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;namespace 自己做分页
{
public class WebForm1 : System.Web.UI.Page
{
private int PageCount;
private int nRecCount;
private int nPage;
private void Page_Load(object sender, System.EventArgs e)
{
PageDisplay();
}
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=你的数据库";
cmd.Connection = conn;
cmd.CommandText = "select 新闻 from 新闻表";
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(" 页次:")
.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(" 页次:")
.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(" 页次:")
.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>
新闻</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();
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;namespace 自己做分页
{
public class WebForm1 : System.Web.UI.Page
{
private int PageCount;
private int nRecCount;
private int nPage;
private void Page_Load(object sender, System.EventArgs e)
{
PageDisplay();
}
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=你的数据库";
cmd.Connection = conn;
cmd.CommandText = "select 新闻 from 新闻表";
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(" 页次:")
.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(" 页次:")
.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(" 页次:")
.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>
新闻</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();
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
解决方案 »
- 如何用Js跨域访问
- 100分求两个正则表达式
- asp.net编写的普通页面嵌入moss门户网站中,怎么获得SharePoint当前登录用户名
- 问一下,为什么我在VS2005调试的好好的!但一发布,数据库是更新了,但显示的数据不更新呢?
- 对asp.net和xhtml的一些问题
- 求一搜索的SQL存储过程?
- 发布本站源程序
- 在asp.net中如何从a.aspx.cs中调用b.aspx.cs中的方法?
- 请问如何在后台对于服务器组件弹出错误或提示窗口!!
- .net时间正序倒序排序
- vs2005中找不到Web Application Projects
- ★ (有偿请教)十万火急,最后一个实现环节,请高中的高手相助!!!
静态页面如果要做搜索.怎么做...
XML存或者HTML存的内容.