AspNetPager绑定DataList

 string g = "select count(*) from News";
 AspNetPager1.RecordCount = Convert.ToInt32(SqlHelper.ExecuteScalar(con, g));
OleDbCommand cmd = new OleDbCommand("select * from News order by GetTime desc", con);
cmd.CommandType = CommandType.Text;
OleDbDataAdapter Sdr = new OleDbDataAdapter();
Sdr.SelectCommand = cmd;
DataSet odr = new DataSet();
Sdr.Fill(odr, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "article");
this.DataList1.DataSource = odr.Tables["article"];
this.DataList1.DataBind();
 //动态设置用户自定义文本内容 以下文本是否生效,要设置ShowCustomInfoSection属性
AspNetPager1.CustomInfoText = "记录总数:<font  color=\"blue\"><b>" + AspNetPager1.RecordCount.ToString() + "</b></font>";
AspNetPager1.CustomInfoText += " 总页数:<font  color=\"blue\"><b>" + AspNetPager1.PageCount.ToString() + "</b></font>";
AspNetPager1.CustomInfoText += " 当前页:<font  color=\"red\"><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font>";
Sdr.Dispose();
con.Close();

你可能感兴趣的:(datalist)