标签:des style blog color os cti
/// <summary> /// Linq分页 /// </summary> int pagesize = 2;//每页条数 int recordcount = 0;//总条数 int pageindex = 1;//当前第几页 public static string con = ConfigurationManager.ConnectionStrings["MySQLDBConnectionString"].ConnectionString; GuestBookDataContext ctx = new GuestBookDataContext(con); public StringBuilder sb = new StringBuilder(); public void GetPage() { if (!String.IsNullOrEmpty(Request.QueryString["page"])) { pageindex = Convert.ToInt32(Request.QueryString["page"]); } recordcount = ctx.tbGuestBook.Count(); int pagecount = (int)Math.Ceiling((decimal)recordcount/pagesize);//总页数 sb.Append("共<font style=‘color:#FF0000‘>"+pageindex+"</font>/"+pagecount+"页 "); for (int i = 1; i <= pagecount; i++) { sb.AppendFormat(@"<a href=‘?page={0}‘>{0}<a/>",i); } var data = (from gb in ctx.tbGuestBook orderby gb.PostTime descending select gb).Skip((pageindex-1)*pagesize).Take(pagesize); rpt_Message.DataSource = data; rpt_Message.DataBind(); }
aspx调用页码代码:
<%=sb.ToString() %>
标签:des style blog color os cti
原文地址:http://www.cnblogs.com/liuswi/p/3822386.html