日期:2014-05-20 浏览次数:20885 次
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(); 
     } 
 }