国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

repeater分頁顯示數據

2019-11-14 16:02:15
字體:
來源:轉載
供稿:網友

 

表名:ChinaStates

控件:Repeater

查詢代碼DA

public class ChinaStatesDA   

{

    PRivate DataClassesDataContext Context;              // 構建LINQ

      public ChinaStatesDA()

      {

        Context = new DataClassesDataContext();

      }

 

public List<ChinaStates> Select(int nowye,int numbers) 

 // 輸入當前頁,頁面數據條數,查詢數據庫信息    

    {

        return Context.ChinaStates.Skip((nowye-1)*numbers).Take(numbers).ToList();

        // .Skip    是跳過多少條數據查詢  .Take查詢前幾條數據    

    }

 

    public int Select()      // 查詢數據庫有多少條數據

    {

        return Context.ChinaStates.Count();   

    }

}

Cs 代碼、;

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

{

    protected void Page_Load(object sender, EventArgs e)   //  運行界面

    {

        if (!IsPostBack)

        {

            bindchinadata(1,5);         // 綁定數據①

             int count = new ChinaStatesDA().Select(); //獲取數據庫多少條數據   

             yeshu = (int)(Math.Ceiling(count / 5.0));

// 計算數據庫一頁5條數據,能顯示多少頁

        }

    }

    private static int yeshu;     //構建總頁數類型   static 表示一直有這個值。

 

private void bindchinadata(int nowye,int numbers)    //綁定數據函數①

   nowye現在第幾頁,numbers每頁顯示數據的個數

    {

        Repeater1.DataSource = new ChinaStatesDA().Select(nowye,numbers);

        Repeater1.DataBind();  

        TextBox1.Text = nowye.ToString();

   // 調用DA中的查詢函數 select 綁定到Repeater 中

// TextBox1.Text 當前的頁數

    }

 

 

 

  protected void Button3_Click(object sender, EventArgs e)       // 下一頁

                                                                                              

    {

        int nowye = int.Parse(TextBox1.Text);        //  構建當前頁面nowye 并賦值

    

        if (yeshu!= nowye)

// 判斷 當前頁面 nowye 是否等于總頁數 yeshu  , 不等于 從新綁定Repeater

        {

            bindchinadata(nowye + 1, 5);

        }

    }

    protected void Button2_Click(object sender, EventArgs e)        // 上一頁

    {

        int nowye = int.Parse(TextBox1.Text);  //  構建當前頁面nowye 并賦值

        if (nowye != 1)

// 判斷 當前頁面 nowye 是否等于第一頁  , 不等于 從新綁定Repeater

{

            bindchinadata(nowye - 1, 5);

        }

    }

    protected void Button5_Click(object sender, EventArgs e)    // 跳轉頁面

    {

        int nowye = int.Parse(TextBox1.Text); //  構建當前頁面nowye 并賦值

        if(nowye>0 && nowye<=yeshu)    //判斷大于0小于總頁數從新綁定Repeater

        {

            bindchinadata(nowye, 5);

        }

    }

    protected void Button1_Click(object sender, EventArgs e)   //首頁

    {

        bindchinadata(1, 5);

    }

    protected void Button4_Click(object sender, EventArgs e) //末頁

    {

        bindchinadata(yeshu, 5);

    }

}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 西城区| 陇南市| 旬邑县| 临西县| 兰坪| 玛纳斯县| 灵武市| 周口市| 房产| 静安区| 天全县| 潜江市| 义马市| 米易县| 根河市| 玉田县| 仁怀市| 汉寿县| 潜江市| 岳西县| 沾益县| 宁陵县| 石河子市| 姚安县| 锡林浩特市| 得荣县| 晋州市| 汝阳县| 陆丰市| 裕民县| 温泉县| 元江| 吉木萨尔县| 枞阳县| 容城县| 台州市| 庆阳市| 乐陵市| 满城县| 讷河市| 衡阳市|