当前位置:编程学习 > C#/ASP.NET >>

用PagedDataSource对datalist分页,但无法显示(请问错在哪啊?)

无论怎么搞datalist都没输出数据!气死我了,搞了半天都不知道什么地方出错。

aspx页面中有个datalist控件,id是DataList1

以下是后台page_load中的代码(其中test1和test2分别是11和120,应该证明pagedatasource的数据源设置正确阿)
------------------------------------------------------------------------
 protected void Page_Load(object sender, EventArgs e)
    {
        string strConnection = ConfigurationManager.ConnectionStrings["newsroomConnectionString"].ConnectionString;
        SqlConnection con = new SqlConnection(strConnection);
        con.Open();
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = new SqlCommand("SELECT * FROM photos WHERE p_date = '2007-6-3'", con);
        DataSet ds = new DataSet();
        da.Fill(ds, "viewpic");
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = ds.Tables["viewpic"].DefaultView;
        string test1 = ds.Tables["viewpic"].Columns.Count.ToString();
        string test2 = ds.Tables["viewpic"].Rows.Count.ToString();
        pds.AllowPaging = true;
        pds.PageSize = 20;
        pds.CurrentPageIndex = 0;
        string test3= pds.DataSourceCount.ToString(); 
        DataList1.DataSource = pds;
        DataList1.DataBind();
    }
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,