?★★★送分快来抢★★★:急寻支持oracle数据库的asp.net(能应用于vs.2003)分页控件,提供首页,尾页,上页,下页,转到某页的翻页功能。
解决方案 »
- 关于模板里DataList数据的刷新
- ■■■■■■■■■■■■■Winform里面做一个小程序,背景图片的问题■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
- 各位救救我,关于文件上传的问题
- asp.net 2.0 cookies 问题
- DropDownList的显示问题.
- 急啊!!向各位高手请教TreeView控件问题!!
- 关于在freetextbox中修改字符的难题,高手请进。
- Table控件生成报表,行和列的格式问题,在线给分
- asp.net运行出错如下!朋友帮忙!急急
- 高手请进....
- 大数据量的处理问题
- 如何将多个hashtable缓存起来?好像无法缓存到dataset里
去下载分页控件,简单稳定,经过无数人的使用和测试
AspNetPager分页控件和用什么数据库没有任何关系,因为它是一个独立的只用于分页的控件,不管数据从哪里来以及如何获取,所以没有所谓不支持Oracle的说法,我做的Oracel项目中就用它来分页。www.webdiyer.com
用不用存储过程都可以,我的示例中不是有用Access数据库分页的示例吗?那些就是没有存储过程的,分页控件不是关心你怎么取数据的,再说Oracle也有存储过程,用存储过程分页效率更高些
/// <summary>
/// 分页控件绑定方法,返回数据集
/// </summary>
/// <param name="myPager">分页控件</param>
/// <param name="sql">要分页的SQL语句</param>
/// <param name="cn">数据库连接串</param>
public DataTable myPageBind(Wuqi.Webdiyer.AspNetPager myPager,string sql,OracleX cn)
{
return(this.myPageBind(myPager,sql,mydata.Config.SysPageSize,cn));
}
/// <summary>
/// 分页控件绑定方法,返回数据集
/// </summary>
/// <param name="myPager">分页控件</param>
/// <param name="sql">要分页的SQL语句</param>
/// <param name="cn">数据库连接串</param>
public DataTable myPageBind(Wuqi.Webdiyer.AspNetPager myPager,string sql,int myPageSize,OracleX cn)
{
//求取记录总数
int mycount = Convert.ToInt32(cn.GetOneValue("select count(*) from (" + sql + ")"));
myPager.RecordCount = mycount; //定义分页数量
myPager.PageSize = myPageSize; //设置分页控件属性
//自定义信息存放位置
myPager.ShowCustomInfoSection = Wuqi.Webdiyer.ShowCustomInfoSection.Left;
//索引文本框显示方式
myPager.ShowInputBox = Wuqi.Webdiyer.ShowInputBox.Always;
//分页信息存放位置
myPager.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Right;
//显示几个页数
myPager.NumericButtonCount = 8;
//是否一定显示分页控件
myPager.AlwaysShow = true;
//使用页面提交方式
myPager.UrlPaging = false;
//不折行
myPager.Wrap = false;
//回到首页
myPager.FirstPageText = "<img src=" + this.MyImgPath() + "/home/firstg.gif border=0 title=\"转到首页\" onmouseover=\"this.src='" + this.MyImgPath() + "/home/firstn.gif'\" onmouseout=\"this.src='" + this.MyImgPath() + "/home/firstg.gif'\">";
//回到上一页
myPager.PrevPageText = "<img src=" + this.MyImgPath() + "/home/prevg.gif border=0 title=\"转到上一页\" onmouseover=\"this.src='" + this.MyImgPath() + "/home/prevn.gif'\" onmouseout=\"this.src='" + this.MyImgPath() + "/home/prevg.gif'\">";
//下一页
myPager.NextPageText = "<img src=" + this.MyImgPath() + "/home/nextg.gif border=0 title=\"转到下一页\" onmouseover=\"this.src='" + this.MyImgPath() + "/home/nextn.gif'\" onmouseout=\"this.src='" + this.MyImgPath() + "/home/nextg.gif'\">";
//最后页
myPager.LastPageText = "<img src=" + this.MyImgPath() + "/home/lastg.gif border=0 title=\"转到最后页\" onmouseover=\"this.src='" + this.MyImgPath() + "/home/lastn.gif'\" onmouseout=\"this.src='" + this.MyImgPath() + "/home/lastg.gif'\">"; //以下设定用户自定义记录信息
myPager.CustomInfoText = "第<font color='red'><b>" + myPager.CurrentPageIndex.ToString() +
"</b></font>页/共<font color='blue'><b>" + myPager.PageCount.ToString() +
"</b></font>页 每页<font color='blue'><b>" + myPager.PageSize.ToString() +
"</b></font>条/共<font color='blue'><b>" + myPager.RecordCount.ToString() +
"</b></font>条"; //根据分页数量绑定分页控件
return(cn.GetDt(sql,(myPager.PageSize * (myPager.CurrentPageIndex - 1)), myPager.PageSize));
}#endregion 结束分页控件
注意事项:
1.cn.GetOneValue:这个是自己写的根据SQL语句返回第一行第一列数据的一个方法
2.cn.GetDt:如下:
/// <summary>
/// 根据开始记录号和欲显示的记录条数生成DataTable
/// </summary>
/// <param name="sql">传递SQL语句</param>
/// <param name="p_start">开始记录号</param>
/// <param name="p_rowCount">欲显示的记录条数</param>
/// <returns>返回DataTable</returns>
public DataTable GetDt(string sql, int p_start, int p_rowCount)
{
OracleDataAdapter myAdp = new OracleDataAdapter(sql, this.cn);
DataSet ds = new DataSet();
try
{
myAdp.Fill(ds,p_start, p_rowCount, "MyPageDataTable");
return(ds.Tables[0]);
}
catch(OracleException ex)
{
throw ex;
}
}3.数据库是oracle,你如果不同可自行修改部分代码即可.
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;namespace localhost
{
/// <summary>
/// Pager 的摘要说明。
/// </summary>
public class Pager : Control
{
private string _UrlFormat;
private int _PageSize;
private int _RecordCount;
private int _PageCount = 5; /// <summary>
/// 连接格式
/// </summary>
public string UrlFormat
{
get
{
return _UrlFormat;
}
set
{
_UrlFormat = value;
}
} /// <summary>
/// 页长度
/// </summary>
public int PageSize
{
get
{
return _PageSize;
}
set
{
_PageSize = value;
}
} /// <summary>
/// 当前页码
/// </summary>
public int PageIndex
{
get
{
string Pageindex = HttpContext.Current.Request.QueryString["PageIndex"];
if ( Pageindex != null )
{
return int.Parse(Pageindex);
}
return 1;
}
} /// <summary>
/// 总记录数
/// </summary>
public int RecordCount
{
get
{
return _RecordCount;
}
set
{
_RecordCount = value;
}
} /// <summary>
/// 两边显示个数
/// </summary>
public int PageCount
{
get
{
return _PageCount;
}
set
{
_PageCount = value;
}
} protected override void Render(HtmlTextWriter writer)
{
int SumPage = (RecordCount + PageSize - 1)/PageSize; int start = PageIndex - PageCount;
int end = PageIndex + PageCount; //以PageIndex为中心,前后个显示Page个页码导航
if (SumPage>(PageCount*2+1))
{
if (start<1)
{
start = 1;
end = start + 10;
}
else if (end>SumPage)
{
start = SumPage - 10;
end = SumPage;
}
}
else
{
start = 1;
end = SumPage;
}
string tmp = "<a href=\"" + UrlFormat + "\">[{0}]</a>";
StringBuilder sb = new StringBuilder();
if (PageIndex > 1)
{
sb.Append(string.Format("<a href=\"" + UrlFormat + "\">首页</a>", 1));
sb.Append(string.Format("<a href=\"" + UrlFormat + "\">上一页</a>", PageIndex - 1));
}
for (int i = start; i <= end; i++)
{
if (i==PageIndex)
{
sb.Append("[" + PageIndex.ToString() + "]");
}
else
{
sb.Append(string.Format(tmp, i));
}
sb.Append(" ");
}
if (PageIndex < SumPage)
{
sb.Append(string.Format("<a href=\"" + UrlFormat + "\">下一页</a>", PageIndex + 1));
sb.Append(string.Format("<a href=\"" + UrlFormat + "\">尾页</a>", SumPage));
}
writer.Write(sb.ToString());
} }
}