AspNetPager在.Net+Access应用总结

代码如下:

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 FrameWork.DB;
using System.Data.OleDb;
using Wuqi.Webdiyer;

namespace FrameWork.web
{
    public partial class Cesi : System.Web.UI.Page
    {
        OleDbConnection MyConn;
        OleDbConnection MyConn1;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                MyConn = FrameWork.DB.DB.CreateDB();
                MyConn.Open();
                string strSql = "select count(*) from News";
                OleDbCommand cmd = new OleDbCommand();
                //指定sql语句
                cmd.CommandText = strSql;
                //指定实例用的连接方法
                cmd.Connection = MyConn;
                AspNetPager1.RecordCount = (int)cmd.ExecuteScalar();
                MyConn.Close();
                BindData();
            }
        }
        //数据绑定
        protected void BindData()
        {
            MyConn1 = FrameWork.DB.DB.CreateDB();
            MyConn1.Open();
            OleDbDataAdapter sda= new OleDbDataAdapter("select * from News",MyConn1);
            DataSet ds = new DataSet();
            sda.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "News");
            GridView1.DataSource = ds.Tables["News"];
            GridView1.DataBind();
            MyConn1.Close();


        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }

    }
}

你可能感兴趣的:(AspNetPager在.Net+Access应用总结)