DataList实现GridView的分页 使用DataList如何实现像GridView那种下面是一排数字的分页? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 前几天看到的http://topic.csdn.net/u/20081130/11/f52eebe9-e6f9-46de-b63a-f637b83aa944.html datalist 没有自带分页,你可以写代码实现,但不如借用第三方快捷。aspnetpager不错的。 private int pageSize = 6; private int i = 1; protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { ViewState["PageCount"] = 1; ViewState["pageIndex"] = 1; BinerToDataList(); IList<Topic> topics = GetAllProducts("select * from bbstopic"); ViewState["PageCount"] = topics.Count / pageSize + 1; i = topics.Count / pageSize+1;//new StringBuilder myt = new StringBuilder(); while (i > 0) { myt.Append("<a href=SectionManager.aspx?p=" + i + ">" + i + "</a> "); i--; } mylink.Text = myt.ToString(); } if (Request.QueryString["p"] != null) { PageIndex = Int32.Parse(Request.QueryString["p"]); BinerToDataList(); } } public int PageIndex { get { return (int)ViewState["pageIndex"]; } set { if ((int)value >= 1 && (int)value <= (int)ViewState["PageCount"]) ViewState["pageIndex"] = value; } } public void BinerToDataList() { IList<Topic> topics = GetAllProducts("SELECT top " + pageSize + " * FROM [bbstopic] where tid not in(select top " + (PageIndex - 1) * pageSize + " tid from [bbstopic])"); // this.DataList1.DataSource = topics; this.DataList1.DataBind(); } public IList<Topic> GetAllProducts(string strsql) { IList<Topic> topics = new List<Topic>(); using (SqlDataReader sdr = SqlHelper.GetReader(strsql)) { while (sdr.Read()) { Topic top = new Topic(); top.TID = (int)sdr["TID"]; top.TlastReply = (DateTime)sdr["TlastReply"]; top.TreplyCount = (int)sdr["TreplyCount"]; top.Tstate = (int)sdr["tstate"]; top.Ttime = (DateTime)sdr["Ttime"]; topics.Add(top); } } return topics; }}记得在前台代码中增加一个HyperLink控件 repeater绑定数据的问题 fileupload实现多个图片上传到指定的文件夹下,并保存路径到数据库 asp.net网站发布 [急]如何用JavaScript获取页面控件Panel的句柄? 有关窗体缩放的问题? 求一条SQL语句 刚才的问题描述有误.重新提问 向周末加班的朋友们推荐源码发布论坛 2.0,c#中获取表单新付值的的内容终始是原来的,修改的没用. asp.net留言板 手头有个大项目,诚招郑州的朋友合作!!! asp.net父子页面弹出与传值问题!重赏! 关于手机付费
http://topic.csdn.net/u/20081130/11/f52eebe9-e6f9-46de-b63a-f637b83aa944.html
{
if (!Page.IsPostBack)
{
ViewState["PageCount"] = 1;
ViewState["pageIndex"] = 1; BinerToDataList();
IList<Topic> topics = GetAllProducts("select * from bbstopic");
ViewState["PageCount"] = topics.Count / pageSize + 1; i = topics.Count / pageSize+1;//new StringBuilder myt = new StringBuilder();
while (i > 0)
{
myt.Append("<a href=SectionManager.aspx?p=" + i + ">" + i + "</a> ");
i--;
} mylink.Text = myt.ToString();
} if (Request.QueryString["p"] != null)
{
PageIndex = Int32.Parse(Request.QueryString["p"]);
BinerToDataList();
}
} public int PageIndex
{
get { return (int)ViewState["pageIndex"]; }
set
{
if ((int)value >= 1 && (int)value <= (int)ViewState["PageCount"])
ViewState["pageIndex"] = value;
}
} public void BinerToDataList()
{
IList<Topic> topics = GetAllProducts("SELECT top " + pageSize + " * FROM [bbstopic] where tid not in(select top " + (PageIndex - 1) * pageSize + " tid from [bbstopic])");
//
this.DataList1.DataSource = topics;
this.DataList1.DataBind();
} public IList<Topic> GetAllProducts(string strsql)
{
IList<Topic> topics = new List<Topic>();
using (SqlDataReader sdr = SqlHelper.GetReader(strsql))
{
while (sdr.Read())
{
Topic top = new Topic(); top.TID = (int)sdr["TID"];
top.TlastReply = (DateTime)sdr["TlastReply"];
top.TreplyCount = (int)sdr["TreplyCount"];
top.Tstate = (int)sdr["tstate"];
top.Ttime = (DateTime)sdr["Ttime"]; topics.Add(top);
}
}
return topics;
}
}记得在前台代码中增加一个HyperLink控件