GIS~沧海浮沉

导航

aspnetpager用法

命名空间中加上:

using System.Data.OleDb;
using Wuqi.Webdiyer;

public partial class showlist : System.Web.UI.Page
{
    DataSet ds;
    OleDbDataAdapter dr;
    OleDbCommand com;

    private void Page_Load(object sender, System.EventArgs e)
    {
        if (!IsPostBack)
        {
            OleDbConnection con = DB.CreatCon();

//DB.cs中为:

//public static OleDbConnection CreatCon()
  //  {
       // return new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|netshopdb.mdb");
   // }
            con.Open();
            com = new OleDbCommand();
            com.Connection = con;
            com.CommandText = "select count(*) from goodsinfo";
            AspNetPager1.AlwaysShow = true;
            AspNetPager1.PageSize = 4;
            AspNetPager1.RecordCount = (int)com.ExecuteScalar();
            con.Close();
            DataListDataBind();
        }
    }
    private void DataListDataBind()
    {
        OleDbConnection con = DB.CreatCon();
        dr = new OleDbDataAdapter("select * from goodsinfo", con);
        ds = new DataSet();
        dr.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "goodsinfo");
        DataList1.DataSource = ds.Tables["goodsinfo"];
        DataList1.DataBind();

    }

 

 

    protected void AspNetPager1_PageChanged(object src, EventArgs e)
    {
               DataListDataBind();
    }

   
}

posted on 2010-09-27 11:59  GIS_Zhou  阅读(210)  评论(0)    收藏  举报