一、前台显示界面代码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_r(Container.DataItem,"osid")%></td>
        <td><%#DataBinder.eval_r(Container.DataItem,"year1")%></td>
        <td><%#DataBinder.eval_r(Container.DataItem,"month1")%></td>
        <td><%#DataBinder.eval_r(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;
        }
    }
}

aspnetpager分页,不使用存储过程的更多相关文章

  1. NHibernate初学三之条件查询(Criteria Queries)与AspNetPager分页实例

    NHibernate除了SQL与HQL两种查询操作外,还有一种就是条件查询Criteria,本文将从网上整理一些Criteria的理论及小实例,最后通过一个结合AspNetPager分页来加深理解,必 ...

  2. .net中实现aspnetpager分页

    第一步首先导入aspnetpager控件,然后再把他从工具箱中拖出,代码如下:  <webdiyer:AspNetPager ID="aspnetpager1" runat= ...

  3. AspNetPager分页控件

    AspNetPager分页控件解决了分页中的很多问题,直接采用该控件进行分页处理,会将繁琐的分页工作变得简单化,下面是我如何使用AspNetPager控件进行分页处理的详细代码:1.首先到www.we ...

  4. 【转】AspNetPager分页控件用法

    AspNetPager分页控件解决了分页中的很多问题,直接采用该控件进行分页处理,会将繁琐的分页工作变得简单化,下面是我如何使用AspNetPager控件进行分页处理的详细代码: 1.首先到www.w ...

  5. AspNetPager分页

    1.页面部分 <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefi ...

  6. 【Bootstrap3.0建站笔记三】AspNetPager分页,每一列都可排序

    1.AspNetPager分页,实现每一列都可排序:           (1).须要将默认排序字段放在HTML页面中.           (2).排序字段放置为td节点的属性. 如图: 实现的效果 ...

  7. 给AspNetPager分页控件添加bootstrap样式

    AspNetPager分页控件算是比较好用的一个分页控件了.想要结合bootstrap使用,官方代码入口 .pagination a[disabled]{ color: #777;cursor: no ...

  8. C# Repeater、webdiyer:AspNetPager分页 AspNetPager分页样式

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/vaecnfeilong/article/details/32712611 AspNetPager分页 ...

  9. PagedDataSource数据绑定控件和AspNetPager分页控件结合使用列表分页

    1.引用AspNetPager.dll. 2.放置Repeater数据绑定控件. <asp:Repeater ID="Repeater1" runat="serve ...

随机推荐

  1. 在美国公司架构中,LLC、LLP 和 Corporation 的区别何在?

    这个问题,首先需要弄清楚这样一个事实:LLC.LLP.Corporation分别属于三种不同类型的公司实体. 1,LLC (Limited Liability Company)是责任有限公司: 2,L ...

  2. (转)Java字符串应用之密码加密与验证

    1.通过java.Security.MessageDigest的静态方法getInstance创建具有指定算法名称的信息摘要,参数为算法名,传入”MD5“则表示使用MD5算法    2.Message ...

  3. SDK编程模板

    #include<Windows.h> LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); int WINAPI WinMain(HINS ...

  4. 从汇编看c++成员函数指针(二)

    下面先看一段c++源码: #include <cstdio> using namespace std; class X { public: virtual int get1() { ; } ...

  5. 自己写的轻量级PHP框架trig与laravel5.1,yii2性能对比

    看了下当前最热门的php开发框架,想对比一下自己写的框架与这些框架的性能对比.先看下当前流行框架的投票情况. 看结果对比,每个测试脚本做了一个数据库的联表查询并进行print_r输出,查询的sql语句 ...

  6. Android 桌面生成快捷方式

    Android生成桌面快捷方式的几种方法: //------------以下为动态替换桌面应用Icon的一种解决方案------------------- // 1.获取本地目录图片的Bitmap ; ...

  7. UI原则之-拼车

    1.简洁------------一目了然,简洁明了 2.易用------------操作方便 3.直观.快速-------快速定位到所需信息 4.友好-------网络延时.超时.等待 5.易懂--- ...

  8. QT:轻松获取网页源码

    获取网页源码的小例子,代码很简单,就不多作解释了. 不过一定要注意网页的编码问题,否则会出现乱码的!!! #include <QtCore> #include <QtNetwork& ...

  9. 【hihocoder 1249 Xiongnu's Land】线性扫描

    2015区域赛北京赛区的三水,当时在赛场上没做出的原因是复杂度分析不正确导致把方法想复杂了.近来复习复杂度分析,觉得不能只是笼统地看渐进复杂度(big-O),更应根据算法的伪码计算真正的以基本操作数为 ...

  10. 【JSP实例】指定用户计数器

    不同的用户访问次数是不一样的,因此对于每一个用户的访问次数都要进行统计,以适应需要. 用户登陆的Login.html的源文件: <html> <head> <title& ...