乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Repeater讀取數(shù)據(jù)并分頁

       悟靜 2012-01-30

      據(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ù)庫(kù)讀出全部數(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();
      }

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多