控件AspNetPager怎样使用。。最好有代码
解决方案 »
- 请问一个关于CKeditor上传按钮的问题
- 请教大师们,如何在html控件的text回车后直接响应事件
- gridview 行ONCLICK事件
- Datalist控件如何实现 编辑 删除?以及分页?
- gzdiablo请进,,接分!!!!!!!!顺便继续问个正则问题.
- 关于方法,很简单的问题
- 关于异常错误的处理:我定义了一个Error.aspx页面,web.config中参数设置:<customErrors defaultRedirect="Error.aspx" mode="Off"> 为什么
- 散分,ZForums V2.0 终于发布。另外,提供FTB1.6.3修改后的源代码
- 表单提交的问题
- 请问如何实现鼠标移动或单击datagrid,该行变色?
- 问下大家(二选一的选择题)
- 怎样把hashtable绑定到datalist中的模板列控件
zhangyj_315的专栏
登录 注册 欢迎 zhubosa! 退出 我的博客 配置 写文章 文章管理 博客首页 全站 当前博客 空间 博客 好友 相册 留言 用户操作
[发私信] [加为好友]
张亚京ID:zhangyj_315共32012次访问,排名4610,好友0人,关注者34人。
熟练使用Dreamweaver、PhotoShop,熟悉HTML语言、CSS、Javascript等;
熟练掌握SQL Server、SQL语句、ASP.NET(C#)、ASP;
掌握VB;
zhangyj_315的文章
原创 86 篇
翻译 0 篇
转载 69 篇
评论 44 篇
订阅我的博客
zhangyj_315的公告
文章分类
AJAX
ASP.NET
ASP.NET面试题
c#基础知识
Div+CSS布局入门教程
IIS
javascript
MySQL
PHP
SQL Server 2005
SQL Server 面试题
在线文本编辑器
存档
2009年08月(1)
2009年07月(3)
2009年06月(1)
2009年05月(3)
2009年04月(7)
2009年03月(11)
2009年02月(11)
2009年01月(8)
2008年12月(1)
2008年10月(3)
2008年09月(5)
2008年08月(5)
2008年07月(2)
2008年06月(13)
2008年05月(22)
2008年04月(20)
2008年03月(39)
AspNetPager分页控件使用方法(一) 收藏
AspNetPager分页控件使用方法
今天做项目时学会一种新控件AspNetPager.dll用法,很想把这方面的经验和大家分享一下,欢迎大家一起进来讨论讨论!
一、前台显示界面代码Default.aspx(注意,代码运行环境是VS.2005)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default4" %>
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>用AspNetPager.dll控件的分页方法操作方法</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table border=1>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td><%#DataBinder.Eval(Container.DataItem,"osid")%></td>
<td><%#DataBinder.Eval(Container.DataItem,"year1")%></td>
<td><%#DataBinder.Eval(Container.DataItem,"month1")%></td>
<td><%#DataBinder.Eval(Container.DataItem,"output1")%></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" Width="100%" NumericButtonCount="6" UrlPaging="true" NumericButtonTextFormatString="[{0}]" CustomInfoHTML="第 <font color='red'><b>%CurrentPageIndex%</b></font> 页 共 %PageCount% 页 显示 %StartRecordIndex%-%EndRecordIndex% 条" ShowCustomInfoSection="left"
FirstPageText="首页" LastPageText="末页" NextPageText="下页" PrevPageText="上页" Font-Names="Arial" BackColor="#F8B500" AlwaysShow="true" ShowInputBox="Always" SubmitButtonText="跳转" SubmitButtonStyle="botton" OnPageChanged="AspNetPager1_PageChanged" >
</webdiyer:AspNetPager>
<%--<webdiyer:AspNetPager ID="AspNetPager1" runat="server" PageSize="15" style="font-size:14px;" HorizontalAlign="Right" NumericButtonCount="6" NumericButtonTextFormatString="[{0}]" CustomInfoHTML="第 <font color='red'><b>%CurrentPageIndex%</b></font> 页 共 %PageCount% 页 显示 %StartRecordIndex%-%EndRecordIndex% 条" InputBoxStyle="width:24px; height:14px;" ShowInputBox="Always" SubmitButtonText=" GO " FirstPageText="[首 页]" PrevPageText="[上 页]" NextPageText="[下 页]" LastPageText="[末 页]" TextBeforeInputBox="转到第" TextAfterInputBox="页 " PagingButtonSpacing="10px" width="100%" ShowCustomInfoSection="Left" UrlPaging="true"></webdiyer:AspNetPager>
--%>
</div>
</form>
</body>
</html>
二、Default.aspx.cs页面的代码
DBAccess db = new DBAccess();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{ BindGrid(); }
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{ BindGrid();
}
public void BindGrid()
{
this.AspNetPager1.RecordCount = Int32.Parse(db.GetAllCount().ToString());
int pageIndex = this.AspNetPager1.CurrentPageIndex - 1;
int pageSize = this.AspNetPager1.PageSize = 20;
Repeater1.DataSource = db.GetCurrentPage(pageIndex, pageSize);
Repeater1.DataBind();
}
三、DBAccess.cs页面的代码
using System.Data.SqlClient;
public class DBAccess
{
private SqlConnection con;
private string DBName = "tongjinet";
//创建连接对象并打开
public void Open()
{
if (con == null)
con = new SqlConnection("server=(local);uid=sa;pwd=sql;database=" + DBName);
if (con.State == ConnectionState.Closed)
con.Open();
}
//创建一个命令对象并返回该对象
public SqlCommand CreateCommand(string sqlStr)
{
Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = sqlStr;
cmd.Connection = con;
return cmd;
}
//生成一个对象并返回该结果集第一行第一列
public object GetScalar(string sqlStr)
{
SqlCommand cmd = CreateCommand(sqlStr);
object obj = cmd.ExecuteScalar();
//CommadnBehavior.CloseConnection是将于DataReader的数据库链接关联起来
//当关闭DataReader对象时候也自动关闭链接
return obj;
}
//执行数据库查询并返回一个数据集 [当前页码,每页记录条数]
public DataSet GetCurrentPage(int pageIndex, int pageSize)
{
//设置导入的起始地址
int firstPage = pageIndex * pageSize;
string sqlStr = "select * from outputsell order by osid desc";
SqlCommand cmd = CreateCommand(sqlStr);
DataSet dataset = new DataSet();
SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd);
dataAdapter.Fill(dataset, firstPage, pageSize, "outputsell");
cmd.Dispose();
Close();
dataAdapter.Dispose();
return dataset;
}
//获得查询数据的总条数
public object GetAllCount()
{
string sqlStr = "select count(*) from outputsell";
object obj = GetScalar(sqlStr);
return obj;
}
//关闭数据库
public void Close()
{
if (con != null)
{
con.Close();
}
}
//释放资源
public void Dispose()
{
if (con != null)
{
con.Dispose();
con = null;
}
}
}
{
try
{
string sql = "select Count(*) FROM coupon WHERE VISIBLE='on'";
int totalOrders = (int)DbSQL.GetSingle(sql);
AspNetPager1.RecordCount = totalOrders;
bindData();
}
catch (Exception ex)
{ MessageBox.Show(Page, "出现异常情况!" + ex.Message); }
}
}
void bindData()
{
try
{
IDataParameter[] parameters = new IDataParameter[]{
new SqlParameter("@startIndex", AspNetPager1.StartRecordIndex),
new SqlParameter("@endindex", AspNetPager1.EndRecordIndex) };
Repeater1.DataSource = DbSQL.RunProcedure("P_GetPageCoupon", parameters, "P_GetPageCoupon");
Repeater1.DataBind();
}
catch (Exception ex)
{ MessageBox.Show(Page, "出现异常情况!" + ex.Message); }
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
bindData();
}