我在网上搜到的一段分页代码,不过使用vs2008写的,里面的好多东西不能用在vs2005,如命名空间、还有数据库连接等。
我想把他改成一个完全可以在vs2005下运行的代码。(改完以后直接复制能使用)
源代码如下:using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class pagination : System.Web.UI.Page
{
public int PageSize = 10; //设置每页显示多少条记录
protected void Page_Load(object sender, EventArgs e)
{
//建立连接
SqlConnection conn = DB.Connection();
conn.Open();
//查看是否已经连接上 Response.Write(conn.State.ToString());
string strSQL = "select count(*) from pagination ";
SqlCommand cmd = new SqlCommand(strSQL, conn);
int MaxSize = Convert.ToInt32(cmd.ExecuteScalar()); //取出总笔数
int Page = Convert.ToInt32(Request.QueryString.Get("PageID")); //获取页码
if (Page == 0)
{
Page = 1;
}
float temp = (float)MaxSize / PageSize;
if (Page >= Convert.ToInt32(Math.Ceiling(temp)))
{
Page = Convert.ToInt32(Math.Ceiling(temp));
}
string SQL = "select top "+PageSize+" * from pagination where UserID>" + (Page - 1) * PageSize;
SqlCommand scmd = new SqlCommand(SQL,conn);
SqlDataReader sdr = scmd.ExecuteReader();
string html = "<table class=table border=1>";
html += "<tr>";
html += "<td width=150px>用 户 名</td>";
html += "<td width=100px>密 码</td>";
html += "<td width=250px>地 址</td>";
html += "</tr>";
while (sdr.Read())
{
html += "<tr>";
html += "<td width=150px>" + sdr["UserName"].ToString() + "</td>";
html += "<td width=100px>" + sdr["UserPwd"].ToString() + "</td>";
html += "<td width=250px>" + sdr["UserAddr"].ToString() + "</td>";
html += "</tr>";
}
html += "</table>"; //关闭连接
sdr.Close();
conn.Close();
show.Text = html;
LblTitle.Text = "ASP.NET分页代码……共有" + Convert.ToInt32(Math.Ceiling(temp)) + "页/当前是第" + Page + "页";
}
protected void BtnFirst_Click(object sender, EventArgs e)
{
Response.Redirect("pagination.aspx?PageID=1");
}
protected void BtnPre_Click(object sender, EventArgs e)
{
int Page = Convert.ToInt32(Request.QueryString.Get("PageID"));
if (Page <= 1)
{
Page = 2;
}
int curent = Page - 1;
Response.Redirect("pagination.aspx?PageID=" + curent);
}
protected void BtnNext_Click(object sender, EventArgs e)
{
SqlConnection conn = DB.Connection();
conn.Open(); string strSQL = "select count(*) from pagination ";
SqlCommand cmd = new SqlCommand(strSQL, conn);
int MaxSize = Convert.ToInt32(cmd.ExecuteScalar()); //取出总笔数
int Page = Convert.ToInt32(Request.QueryString.Get("PageID"));
float temp = (float)MaxSize / PageSize;
if (Page >= Convert.ToInt32(Math.Ceiling(temp)))
{
Page = Convert.ToInt32(Math.Ceiling(temp))-1;
}
if (Page <= 0)
{
Page = 1;
}
int curent = Page + 1;
Response.Redirect("pagination.aspx?PageID=" + curent);
conn.Close();
}
protected void BtnLast_Click(object sender, EventArgs e)
{
SqlConnection conn = DB.Connection();
conn.Open();
string strSQL = "select count(*) from pagination ";
SqlCommand cmd = new SqlCommand(strSQL, conn);
int MaxSize = Convert.ToInt32(cmd.ExecuteScalar()); //取出总笔数
float temp = (float)MaxSize / PageSize;
Response.Redirect("pagination.aspx?PageID=" + Math.Ceiling(temp));
conn.Close();
}
}
我想把他改成一个完全可以在vs2005下运行的代码。(改完以后直接复制能使用)
源代码如下:using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class pagination : System.Web.UI.Page
{
public int PageSize = 10; //设置每页显示多少条记录
protected void Page_Load(object sender, EventArgs e)
{
//建立连接
SqlConnection conn = DB.Connection();
conn.Open();
//查看是否已经连接上 Response.Write(conn.State.ToString());
string strSQL = "select count(*) from pagination ";
SqlCommand cmd = new SqlCommand(strSQL, conn);
int MaxSize = Convert.ToInt32(cmd.ExecuteScalar()); //取出总笔数
int Page = Convert.ToInt32(Request.QueryString.Get("PageID")); //获取页码
if (Page == 0)
{
Page = 1;
}
float temp = (float)MaxSize / PageSize;
if (Page >= Convert.ToInt32(Math.Ceiling(temp)))
{
Page = Convert.ToInt32(Math.Ceiling(temp));
}
string SQL = "select top "+PageSize+" * from pagination where UserID>" + (Page - 1) * PageSize;
SqlCommand scmd = new SqlCommand(SQL,conn);
SqlDataReader sdr = scmd.ExecuteReader();
string html = "<table class=table border=1>";
html += "<tr>";
html += "<td width=150px>用 户 名</td>";
html += "<td width=100px>密 码</td>";
html += "<td width=250px>地 址</td>";
html += "</tr>";
while (sdr.Read())
{
html += "<tr>";
html += "<td width=150px>" + sdr["UserName"].ToString() + "</td>";
html += "<td width=100px>" + sdr["UserPwd"].ToString() + "</td>";
html += "<td width=250px>" + sdr["UserAddr"].ToString() + "</td>";
html += "</tr>";
}
html += "</table>"; //关闭连接
sdr.Close();
conn.Close();
show.Text = html;
LblTitle.Text = "ASP.NET分页代码……共有" + Convert.ToInt32(Math.Ceiling(temp)) + "页/当前是第" + Page + "页";
}
protected void BtnFirst_Click(object sender, EventArgs e)
{
Response.Redirect("pagination.aspx?PageID=1");
}
protected void BtnPre_Click(object sender, EventArgs e)
{
int Page = Convert.ToInt32(Request.QueryString.Get("PageID"));
if (Page <= 1)
{
Page = 2;
}
int curent = Page - 1;
Response.Redirect("pagination.aspx?PageID=" + curent);
}
protected void BtnNext_Click(object sender, EventArgs e)
{
SqlConnection conn = DB.Connection();
conn.Open(); string strSQL = "select count(*) from pagination ";
SqlCommand cmd = new SqlCommand(strSQL, conn);
int MaxSize = Convert.ToInt32(cmd.ExecuteScalar()); //取出总笔数
int Page = Convert.ToInt32(Request.QueryString.Get("PageID"));
float temp = (float)MaxSize / PageSize;
if (Page >= Convert.ToInt32(Math.Ceiling(temp)))
{
Page = Convert.ToInt32(Math.Ceiling(temp))-1;
}
if (Page <= 0)
{
Page = 1;
}
int curent = Page + 1;
Response.Redirect("pagination.aspx?PageID=" + curent);
conn.Close();
}
protected void BtnLast_Click(object sender, EventArgs e)
{
SqlConnection conn = DB.Connection();
conn.Open();
string strSQL = "select count(*) from pagination ";
SqlCommand cmd = new SqlCommand(strSQL, conn);
int MaxSize = Convert.ToInt32(cmd.ExecuteScalar()); //取出总笔数
float temp = (float)MaxSize / PageSize;
Response.Redirect("pagination.aspx?PageID=" + Math.Ceiling(temp));
conn.Close();
}
}
解决方案 »
- xml问题?????
- 把类放进viewstate,提示需要序列化。加了[Serializable]之后,好了。然后又让类继承其他类,又提示需要加序列化。。。
- 问一个VSS的问题
- ASP session无故失效
- 截取字符串问题
- 求助高手asp.net如何限制标题的字数
- VS2005 中,如何手动为 WebControl(Page) 添加事件处理程序?
- DropDownlist的绑定问题?急!
- 如何用JS来控件一个DIV的位置
- ASP.Net的环境怎样配制才行?aspx文件都无法浏览。急,在线等。
- JS验证不通过后,如何不再去执行按钮事件?
- Enterprise Library 中 Instrumentation的介绍哪里有?
http://blog.csdn.net/46539492/archive/2008/04/11/2283360.aspx
http://blog.csdn.net/46539492/archive/2008/04/02/2244627.aspx
http://www.webdiyer.com/AspNetPager/default.aspx
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
public partial class pagination : System.Web.UI.Page
{
public int PageSize = 10; //设置每页显示多少条记录
protected void Page_Load(object sender, EventArgs e)
{
//建立连接
//SqlConnection conn = DB.Connection();
SqlConnection conn = new SqlConnection("server=.;database=xx;uid=xx;pwd=xx");
conn.Open();
//查看是否已经连接上 Response.Write(conn.State.ToString());
string strSQL = "select count(*) from pagination ";
SqlCommand cmd = new SqlCommand(strSQL, conn);
int MaxSize = Convert.ToInt32(cmd.ExecuteScalar()); //取出总笔数
int Page = Convert.ToInt32(Request.QueryString.Get("PageID")); //获取页码
if (Page == 0)
{
Page = 1;
}
float temp = (float)MaxSize / PageSize;
if (Page >= Convert.ToInt32(Math.Ceiling(temp)))
{
Page = Convert.ToInt32(Math.Ceiling(temp));
}
string SQL = "select top " + PageSize + " * from pagination where UserID>" + (Page - 1) * PageSize;
SqlCommand scmd = new SqlCommand(SQL, conn);
SqlDataReader sdr = scmd.ExecuteReader();
string html = "<table class=table border=1>";
html += "<tr>";
html += "<td width=150px>用 户 名</td>";
html += "<td width=100px>密 码</td>";
html += "<td width=250px>地 址</td>";
html += "</tr>";
while (sdr.Read())
{
html += "<tr>";
html += "<td width=150px>" + sdr["UserName"].ToString() + "</td>";
html += "<td width=100px>" + sdr["UserPwd"].ToString() + "</td>";
html += "<td width=250px>" + sdr["UserAddr"].ToString() + "</td>";
html += "</tr>";
}
html += "</table>"; //关闭连接
sdr.Close();
conn.Close(); //页面上的控件先注释
//show.Text = html;
//LblTitle.Text = "ASP.NET分页代码……共有" + Convert.ToInt32(Math.Ceiling(temp)) + "页/当前是第" + Page + "页"; }
protected void BtnFirst_Click(object sender, EventArgs e)
{
Response.Redirect("pagination.aspx?PageID=1");
}
protected void BtnPre_Click(object sender, EventArgs e)
{
int Page = Convert.ToInt32(Request.QueryString.Get("PageID"));
if (Page <= 1)
{
Page = 2;
}
int curent = Page - 1;
Response.Redirect("pagination.aspx?PageID=" + curent);
}
protected void BtnNext_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server=.;database=xx;uid=xx;pwd=xx");
conn.Open(); string strSQL = "select count(*) from pagination ";
SqlCommand cmd = new SqlCommand(strSQL, conn);
int MaxSize = Convert.ToInt32(cmd.ExecuteScalar()); //取出总笔数
int Page = Convert.ToInt32(Request.QueryString.Get("PageID"));
float temp = (float)MaxSize / PageSize;
if (Page >= Convert.ToInt32(Math.Ceiling(temp)))
{
Page = Convert.ToInt32(Math.Ceiling(temp)) - 1;
}
if (Page <= 0)
{
Page = 1;
}
int curent = Page + 1;
Response.Redirect("pagination.aspx?PageID=" + curent);
conn.Close();
}
protected void BtnLast_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server=.;database=xx;uid=xx;pwd=xx");
conn.Open();
string strSQL = "select count(*) from pagination ";
SqlCommand cmd = new SqlCommand(strSQL, conn);
int MaxSize = Convert.ToInt32(cmd.ExecuteScalar()); //取出总笔数
float temp = (float)MaxSize / PageSize;
Response.Redirect("pagination.aspx?PageID=" + Math.Ceiling(temp));
conn.Close();
}
}
string SQL = "select top "+PageSize.ToString()+" * from pagination where UserID not in (select top " + ((Page - 1) * PageSize).ToString() + " userid from pagination )";
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
public partial class pagination : System.Web.UI.Page
{
public int PageSize = 10; //设置每页显示多少条记录
protected void Page_Load(object sender, EventArgs e)
{
//建立连接
string StrConn=ConfigurationManager.AppSetting["ConnectionString"];
SqlConnection conn = new SqlConnection(StrConn); conn.Open();
//查看是否已经连接上 Response.Write(conn.State.ToString());
string strSQL = "select count(*) from pagination ";
SqlCommand cmd = new SqlCommand(strSQL, conn);
int MaxSize = Convert.ToInt32(cmd.ExecuteScalar()); //取出总笔数
int Page = Convert.ToInt32(Request.QueryString.Get("PageID")); //获取页码
if (Page == 0)
{
Page = 1;
}
float temp = (float)MaxSize / PageSize;
if (Page >= Convert.ToInt32(Math.Ceiling(temp)))
{
Page = Convert.ToInt32(Math.Ceiling(temp));
}
string SQL = "select top "+PageSize+" * from pagination where UserID>" + (Page - 1) * PageSize;
SqlCommand scmd = new SqlCommand(SQL,conn);
SqlDataReader sdr = scmd.ExecuteReader();
string html = "<table class=table border=1>";
html += "<tr>";
html += "<td width=150px>用 户 名</td>";
html += "<td width=100px>密 码</td>";
html += "<td width=250px>地 址</td>";
html += "</tr>";
while (sdr.Read())
{
html += "<tr>";
html += "<td width=150px>" + sdr["UserName"].ToString() + "</td>";
html += "<td width=100px>" + sdr["UserPwd"].ToString() + "</td>";
html += "<td width=250px>" + sdr["UserAddr"].ToString() + "</td>";
html += "</tr>";
}
html += "</table>"; //关闭连接
sdr.Close();
conn.Close();
show.Text = html;
LblTitle.Text = "ASP.NET分页代码……共有" + Convert.ToInt32(Math.Ceiling(temp)) + "页/当前是第" + Page + "页";
}
protected void BtnFirst_Click(object sender, EventArgs e)
{
Response.Redirect("pagination.aspx?PageID=1");
}
protected void BtnPre_Click(object sender, EventArgs e)
{
int Page = Convert.ToInt32(Request.QueryString.Get("PageID"));
if (Page <= 1)
{
Page = 2;
}
int curent = Page - 1;
Response.Redirect("pagination.aspx?PageID=" + curent);
}
protected void BtnNext_Click(object sender, EventArgs e)
{
SqlConnection conn = DB.Connection();
conn.Open(); string strSQL = "select count(*) from pagination ";
SqlCommand cmd = new SqlCommand(strSQL, conn);
int MaxSize = Convert.ToInt32(cmd.ExecuteScalar()); //取出总笔数
int Page = Convert.ToInt32(Request.QueryString.Get("PageID"));
float temp = (float)MaxSize / PageSize;
if (Page >= Convert.ToInt32(Math.Ceiling(temp)))
{
Page = Convert.ToInt32(Math.Ceiling(temp))-1;
}
if (Page <= 0)
{
Page = 1;
}
int curent = Page + 1;
Response.Redirect("pagination.aspx?PageID=" + curent);
conn.Close();
}
protected void BtnLast_Click(object sender, EventArgs e)
{
SqlConnection conn = DB.Connection();
conn.Open();
string strSQL = "select count(*) from pagination ";
SqlCommand cmd = new SqlCommand(strSQL, conn);
int MaxSize = Convert.ToInt32(cmd.ExecuteScalar()); //取出总笔数
float temp = (float)MaxSize / PageSize;
Response.Redirect("pagination.aspx?PageID=" + Math.Ceiling(temp));
conn.Close();
}
}
1。“ASP.index_aspx.GetTypeHashCode()”: 没有找到适合的方法来重写 2。“ASP.index_aspx.ProcessRequest(System.Web.HttpContext)”: 没有找到适合的方法来重写 3.“ASP.index_aspx”不会实现接口成员“System.Web.IHttpHandler.IsReusable”
如上一页 OnClick="BtnPre_Click"