关于datalist分页问题,兄弟姐妹们,帮我看看,这样没效果出来,帮我看看问题出在哪?using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.IO;public partial class product : System.Web.UI.Page
{
    protected static int page = 1; 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bind();
        }
    }
    void bind()
    {
        
        OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\c#\\App_Data\\DB_SP.mdb;");
        con.Open();        if (Request["type"] == null)
        {
            OleDbCommand com = new OleDbCommand("select * from pjian", con);
            OleDbDataAdapter da = new OleDbDataAdapter(com);
            DataTable table = new DataTable();
            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = table.DefaultView;
            pds.AllowPaging = true;
            pds.PageSize = 12;            if (page > pds.PageCount)
                page = pds.PageCount;
            if (page < 1)
                page = 1;            pds.CurrentPageIndex = page - 1;
            lalPageCount.Text = pds.PageCount.ToString();
            Label4.Text = page.ToString();
            Label5.Text = Convert.ToString(pds.DataSourceCount);            if (DropDownList1.Items.Count == 0)
            {
                for (int i = 1; i < Convert.ToUInt32(pds.PageCount); i++)
                {
                    DropDownList1.Items.Add(new ListItem(i.ToString()));
                }
            }
            da.Fill(table);
            Response.Write(pds);
            dlProducts.DataSource = pds;
            dlProducts.DataBind();
        }
        else
        {
            string title = Request["type"].ToString();
            Label2.Text = "<&nbsp;" + title;            OleDbDataAdapter oda2 = new OleDbDataAdapter("select * from pjian where pcname='" + title + "'", con);
            DataTable dt2 = new DataTable();
            oda2.Fill(dt2);            dlProducts.DataSource = dt2;
            dlProducts.DataBind();
        }
        con.Close();
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        page -= 1;
        bind(); 
    }
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        page += 1;
        bind(); 
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        page = 1;
        bind(); 
    }
    protected void LinkButton4_Click(object sender, EventArgs e)
    {
        page = Int32.Parse(lalPageCount.Text);
        bind();
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        page = Int32.Parse(DropDownList1.SelectedValue.ToString());
        bind(); 
    }
}

解决方案 »

  1.   

                //OleDbCommand com = new OleDbCommand("select * from pjian", con); 
                string sql="select * from pjian";
                OleDbDataAdapter da = new OleDbDataAdapter(sql,con); 
                DataSet ds=new DataSet();
                da.fill(ds,"pjian");
                DataTable table;
                table=ds.tables["pjian"]; 
                PagedDataSource pds = new PagedDataSource(); 
                pds.DataSource = table.DefaultView; 
      

  2.   

    哦,知道了是dataset
    我从另外的也面个、拷贝过来的,没注意,多谢大家