日期:2014-05-20  浏览次数:20685 次

asp.net一个主题文章,里面要分页进行说明,就像很多服装网站那样 求助
asp.net(C#)中,现在我做一个文章系统,有的文章常并且不合适放在一个页面中,想分成好几页显示,而且不是读取出来用一个列,比如:上一页123456下一页 ,我感觉不应该是放在一个字段中的,并且添加文章的时候就应该是分开录入的吧?菜鸟没经验,查了半天也没查出来结果。

我认为文章应该按页贮存在数据库中,
而不是按文章把全文放在一条记录里,这里就可以直接分页了,
 但是我不知道该怎么做, 求助。谢谢

 这样显示,具体怎么做啊?各位高手能否详细讲讲,在下不胜感激!!越详细越好!


------解决方案--------------------
一般来说,通用的大型内容管理系统是会把内容数据做为html页面的片段直接存储为shtm或htm数据,再阅读时使用外层模板页套上后再呈现,存在数据库里的话,小系统没问题,当你的数据达到几十G的时候就悲剧了,分布什么的也不好做。通常的分页都是由内容采集、编辑人员设置好的,自动的分页也有但一般来说很不实用,会造成布局混乱。也就是说编辑好1.htm,2.htm,3.htm,4.htm。
------解决方案--------------------
C# code

using System; 

 using System.Collections; 

 using System.Configuration; 

 using System.Data; 

 using System.Linq; 

 using System.Web; 

 using System.Web.Security; 

 using System.Web.UI; 

 using System.Web.UI.HtmlControls; 

 using System.Web.UI.WebControls; 

 using System.Web.UI.WebControls.WebParts; 

 using System.Xml.Linq; 

 using System.Data.SqlClient;    

 public partial class databind : System.Web.UI.Page 

 {       
     protected void Page_Load(object sender, EventArgs e) 

     { 

         if (!IsPostBack) 

         { 

             num.Text = "1"; 
             repdatabind();  

         }     

     } 

     public void repdatabind() 

     { 

         string connstring = ConfigurationManager.ConnectionStrings["AdventureWorksDWConnectionString"].ConnectionString; 

         SqlConnection con = new SqlConnection(connstring); 

         SqlConnection conn = new SqlConnection(); 

         DataSet ds = new DataSet(); 

         SqlDataAdapter sda = new SqlDataAdapter("select * from DimProduct", con); 

         sda.Fill(ds, "name"); 

         PagedDataSource pds = new PagedDataSource(); 

         pds.DataSource = ds.Tables["name"].DefaultView; 

         pds.AllowPaging = true;//允许分页 

         pds.PageSize = 8;//单页显示项数 

   

         int curpage = Convert.ToInt32(num.Text); 

         this.BtnDown.Enabled = true; 

         this.BtnUp.Enabled = true; 

         pds.CurrentPageIndex = curpage - 1; 

         if (curpage == 1) 

         { 

             this.BtnUp.Enabled = false; 

         } 

         if (curpage == pds.PageCount) 

         { 

             this.BtnDown.Enabled = false; 

         } 

         this.Repeater1.DataSource = pds; 

         this.Repeater1.DataBind(); 

     } 

    

     protected void BtnUp_Click(object sender, EventArgs e) 

     { 

         this.num.Text =Convert.ToString ( Convert.ToInt32(num.Text)- 1) ; 

         repdatabind(); 

     } 

     protected void BtnDown_Click(object sender, EventArgs e) 

     { 

         this.num.Text = Convert.ToString(Convert.ToInt32(num.Text)+ 1) ; 

         repdatabind(); 
     } 

 }