using System;
using System.IO;
using System.Web;namespace MyPage
{
public class Pager
{
public Pager(){} public string setcolor(int i,string color1,string color2)
{
if (i % 2 == 0) {
return color1;
} else {
return color2;
}
} //判断第几页
public int DealPageNo(string PageNo)
{
if (PageNo!= null) {
return 1;
} else {
return Convert.ToInt32(PageNo);
}
}
//SQL = PageSQL(pageNo,PageSize,"Article","*","ID","CLASSID = " & request("classid"),"addtime desc")
public string PageSQL(string PageNo,string PageSize,string Table,string Word,string Key,string where,string OrderBy)
{
string tempSql,strSelect1,strSelect2,strSelect3;
int iPageNo;
int iPageSize;
tempSql = "";
iPageNo = DealPageNo(PageNo);
iPageSize = Convert.ToInt32(PageSize);
if ((iPageNo == 1)) {
tempSql = "select top " + iPageSize + " " + Word + " from " + Table;
if ((where != "")) {
tempSql = tempSql + " where " + where;
}
if ((OrderBy != "")) {
tempSql = tempSql + " order by " + OrderBy;
}
} else {
strSelect1 = "select top " + iPageSize + " " + Word + " from " + Table + " where " + Key + " NOT IN (";
strSelect2 = "select top " + iPageSize * (iPageNo - 1) + " " + Key + " from " + Table;
strSelect3 = ") ";
if ((where != "")) {
strSelect2 = strSelect2 + " where " + where;
strSelect3 = strSelect3 + " and (" + where + ")";
}
if ((OrderBy != "")) {
strSelect2 = strSelect2 + " order by " + OrderBy;
strSelect3 = strSelect3 + " order by " + OrderBy;
}
tempSql = strSelect1 + strSelect2 + strSelect3;
}
return tempSql;
}
public string CountSql(string Table,string Where)
{
string tempSql;
tempSql = "select count(*) from " + Table;
if ((Where != "")) {
tempSql = tempSql + " where " + Where;
}
return tempSql;
}
public string pageing_msg(int Count,int pageSize,int pageNo)
{
string s = "";
int PageCount = 0;
PageCount = Convert.ToInt32((Count + pageSize - 1) / pageSize);
s = "共有<b><font color=\"#990000\">" + Count + "</font></b>条信息";
s = s + " 分<b><font color=\"#990000\">" + PageCount + "</font></b>页";
s = s + " 当前页:<b><font color=\"#990000\">" + pageNo + "</font></b>";
return s;
}
}
}
using System.IO;
using System.Web;namespace MyPage
{
public class Pager
{
public Pager(){} public string setcolor(int i,string color1,string color2)
{
if (i % 2 == 0) {
return color1;
} else {
return color2;
}
} //判断第几页
public int DealPageNo(string PageNo)
{
if (PageNo!= null) {
return 1;
} else {
return Convert.ToInt32(PageNo);
}
}
//SQL = PageSQL(pageNo,PageSize,"Article","*","ID","CLASSID = " & request("classid"),"addtime desc")
public string PageSQL(string PageNo,string PageSize,string Table,string Word,string Key,string where,string OrderBy)
{
string tempSql,strSelect1,strSelect2,strSelect3;
int iPageNo;
int iPageSize;
tempSql = "";
iPageNo = DealPageNo(PageNo);
iPageSize = Convert.ToInt32(PageSize);
if ((iPageNo == 1)) {
tempSql = "select top " + iPageSize + " " + Word + " from " + Table;
if ((where != "")) {
tempSql = tempSql + " where " + where;
}
if ((OrderBy != "")) {
tempSql = tempSql + " order by " + OrderBy;
}
} else {
strSelect1 = "select top " + iPageSize + " " + Word + " from " + Table + " where " + Key + " NOT IN (";
strSelect2 = "select top " + iPageSize * (iPageNo - 1) + " " + Key + " from " + Table;
strSelect3 = ") ";
if ((where != "")) {
strSelect2 = strSelect2 + " where " + where;
strSelect3 = strSelect3 + " and (" + where + ")";
}
if ((OrderBy != "")) {
strSelect2 = strSelect2 + " order by " + OrderBy;
strSelect3 = strSelect3 + " order by " + OrderBy;
}
tempSql = strSelect1 + strSelect2 + strSelect3;
}
return tempSql;
}
public string CountSql(string Table,string Where)
{
string tempSql;
tempSql = "select count(*) from " + Table;
if ((Where != "")) {
tempSql = tempSql + " where " + Where;
}
return tempSql;
}
public string pageing_msg(int Count,int pageSize,int pageNo)
{
string s = "";
int PageCount = 0;
PageCount = Convert.ToInt32((Count + pageSize - 1) / pageSize);
s = "共有<b><font color=\"#990000\">" + Count + "</font></b>条信息";
s = s + " 分<b><font color=\"#990000\">" + PageCount + "</font></b>页";
s = s + " 当前页:<b><font color=\"#990000\">" + pageNo + "</font></b>";
return s;
}
}
}
解决方案 »
- 控件textBox的颜色怎么改变不了 ?
- 求助!关于使用ajaxpro以后页面控件不能正常赋值问题
- |M|我下载了PetShop4.0但安装以后里面有好多的文件夹 我想问一下除了web文件夹外其他文件夹是用来做什么的。。可不可不以要啊
- 文本框输入问题
- 从另一台计算机的web工程复制到本机,打开xxx.csproj,报错提示内容如下:(请问应该如何解决啊?) 急,急,急
- 急求C#做的网络视频播放器,在线等待,帮帮我吧,高手!
- OCX的问题,希望给予帮助,挺急的..
- 各位是如何管理自己的资料的?用什么软件?
- 关于往DataTable动态增加一行数据的求解
- 图片显示问题!!急
- 求助:vs.net 2005下的开发两个问题,望高手赐教
- 请问如何实现两个WebForm间的数据传送
我自己写的控件只包含分页的逻辑,数据来源是放在数据层里做的,返回dataset
而显示分页的样式则是用用户控件,好处是可以随意定义外表,现在流行嘛,呵呵
<asp:Label ID="PageCount"
runat="server" Text=""></asp:Label>
<asp:Label ID="RecordCount" runat="server"
Text=""></asp:Label>
<asp:LinkButton ID="btnFist" runat="server" CommandArgument="Fist" OnClick="PageChange">首页</asp:LinkButton>
<asp:LinkButton ID="btnPrev" runat="server" CommandArgument="Prev" OnClick="PageChange">上一页</asp:LinkButton>
<asp:LinkButton ID="btnNext" runat="server" CommandArgument="Next" OnClick="PageChange">下一页</asp:LinkButton>
<asp:LinkButton ID="btnLast" runat="server" CommandArgument="Last" OnClick="PageChange">尾页</asp:LinkButton>
跳转<input id="txtNum" style="width: 24px" type="text" runat="server" />页
<asp:Button ID="btnGo" runat="server" Text="Go" OnClick="btnGo_Click" />asp.cs:
public void PageChange(object sender, EventArgs e)//分页
{
string direction = ((LinkButton)sender).CommandArgument;
switch (direction)
{
case "Fist":
GridView1.PageIndex = 0;
break;
case "Prev":
GridView1.PageIndex =Math.Max(GridView1.PageIndex - 1, 0);
break;
case "Next":
GridView1.PageIndex =Math.Min(GridView1.PageIndex + 1,GridView1.PageCount - 1);
break;
case "Last":
GridView1.PageIndex = GridView1.PageCount - 1;
break;
default:
break;
}
GetDataBind();
}
private void GetDataBind()//绑定
{
BLL bll=new BLL ();
GridView1.DataSource = bll.GetBookTable().DefaultView;
GridView1.DataBind();
this.Current.Text = "第" + (GridView1.PageIndex + 1).ToString() + "页";
this.PageCount.Text = "共" + GridView1.PageCount.ToString() + "页";
this.RecordCount.Text = "总共" + bll.GetBookTable().Rows.Count.ToString() + "条记录";
if (GridView1.PageIndex == 0)
{
btnFist.Visible = false;
btnPrev.Visible = false;
}
else
{
btnFist.Visible = true;
btnPrev.Visible = true;
}
if (GridView1.PageIndex == GridView1.PageCount - 1)
{
btnNext.Visible = false;
btnLast.Visible = false;
}
else
{
btnNext.Visible = true;
btnLast.Visible = true;
} }
protected void btnGo_Click(object sender, EventArgs e)//跳转
{
if (Int32.Parse(txtNum.Value.Trim()) <= GridView1.PageCount)
{
GridView1.PageIndex = (Convert.ToInt32(txtNum.Value.Trim()) - 1);
}
else
{
RegisterStartupScript("", "<script>alert('页码不能大于总页数')</script>");
}
GetDataBind();
}
public int DealPageNo(string PageNo)
{
if (PageNo!= null) {
return 1;
} else {
return Convert.ToInt32(PageNo);
}
}=================
没有考虑到非数字,或者小于等于0
用来计算又多少页,严重错误,没有考虑Int数据类型自己四舍五入。
有时候漏算一页,多一页 /// <summary>
/// 计算分页--进一法
/// </summary>
/// <param name="TotalNo">有N行数据</param>
/// <param name="PageSize">每页显示N行</param>
/// <returns>分页后有X页</returns>
public static int CutPage(double TotalNo, double PageSize)
{
return (int)Math.Ceiling(TotalNo / PageSize);
}
刚刚发的免费控件,用.net编程的话使用高效率的控件比较快,这是我的想法