據(jù)說這個(gè)沒有什么用,,但是把這個(gè)搞懂了對(duì)datagri和datalist和有幫助,事業(yè)就筆記一下了,。 ----------控件清單--------- Panel Panel1; Button Button1; Button Button2; Label Label1; Label Label2; Label Label3; Label Label4; Label Label5; Repeater Repeater1;
--------------------------.cs頁----------------------------------- private void Page_Load(object sender, System.EventArgs e) { if(!this.IsPostBack) { this.Label1.Text="1"; this.fill(); } } private void fill() { int pag=Convert.ToInt32(this.Label1.Text);//設(shè)置當(dāng)前頁 SqlConnection con=new SqlConnection("server=.;database=Northwind;uid=sa;pwd=980123;");//實(shí)例化連接 SqlDataAdapter sda=new SqlDataAdapter();//建立一個(gè)數(shù)據(jù)適配器對(duì)象 sda.SelectCommand=new SqlCommand("select * from Employees",con);//實(shí)例化SelectCommand,,并用他從數(shù)據(jù)庫讀出全部數(shù)據(jù) DataSet ds=new DataSet();//定義一個(gè)數(shù)據(jù)集填充 sda.Fill(ds,"name");//使用適配器填充數(shù)據(jù)集到本地表“name” PagedDataSource ps=new PagedDataSource();//實(shí)例化一個(gè)PagedDataSource,這個(gè)本來是封裝是DATAGRID里面的 ps.DataSource=ds.Tables["name"].DefaultView;//設(shè)置他的數(shù)據(jù)源為ds.Tables["name"].DefaultView數(shù)據(jù)視圖 ps.AllowPaging=true;//允許分頁 ps.PageSize=3;//每頁顯示數(shù)量 ps.CurrentPageIndex=pag-1;//當(dāng)前頁碼,,因?yàn)轫撌菑?開始的,,所以要減1 this.Button1.Enabled=true;//按鈕當(dāng)前狀態(tài) this.Button2.Enabled=true; this.Label5.Text=ps.PageCount.ToString(); if(pag==1) { this.Button1.Enabled=false;//如果當(dāng)前頁是 1 ,上一頁按鈕不可用 } if(pag==ps.PageCount) { this.Button2.Enabled=false;//如果當(dāng)前頁是最后一頁 ,,下一頁按鈕不可用 } this.Repeater1.DataSource=ps; this.Repeater1.DataBind(); } 窗體代碼 private void Button2_Click(object sender, System.EventArgs e) { this.Label1.Text=((Convert.ToInt32(this.Label1.Text))+1).ToString(); this.fill(); }
private void Button1_Click(object sender, System.EventArgs e) { this.Label1.Text=((Convert.ToInt32(this.Label1.Text))-1).ToString(); this.fill(); }
|