分頁之C#封裝預存程序

來源:互聯網
上載者:User

標籤:分頁控制項   io   ar   os   使用   sp   資料   on   問題   

DAL層:

public DataTable GetDataByPage(int pageIndex,int pageSize,out int totalcount)

{

 totalcount=0;

 //1.0 定義預存程序的名字,一定是在資料庫存在的預存程序

 string prodname="USP_GetListByPage";

 //2.0 定義預存程序需要的參數數組

 SqlParameter[] params=new SqlParameter[]{

  new SqlParameter("@pageIndex",pageIndex),

  new SqlParameter("@pageSize",pageSize),

  new SqlParameter("@totalcount",totalcount)

};

 //3.0 由於totalcount在預存程序中的參數類型為OUTPUT,所以在此要增加對其的描述

 params[2].Direction=ParameterDirection.Output;

 //4.0 開始執行,注意執行一定是在擷取params[2].Value之前運行,否則擷取不到真正的合格資料行數totalcount

 DataSet dt=DbHelperSQL.RunProcedure(prodname,params,"list");

 if(params[2].Value!=null)

{

  totalcount=int.Parse(params[2].Value.ToString());

}

 return ds.Tables[0];

}

 

BLL層:

public List<表實體>   GetListByPage(int pageIndex,int pageSize,out int totalcount)

{

  DataTable dt=dal.GetListByPage(pageIndex,pageSize,out totalcount);

  return DataTableToList(dt);

}

 

Site層:

public void GetListByPage()

{

    //1.0 接受ajax請求或者url請求傳遞過來的參數

    string pageIndex=Request.QueryString["pageIndex"];

    string pageSize=Request.Querystrinig["pageSize"];

    //2.0 參數合法性驗證,判斷是否為Int

    ..........

    //3.0 把pageIndex和pageSize轉為int,作為參數傳遞

    int ipageIndex=int.Parse(pageIndex);

    int ipageSize=int.Parse(pageSize);

    int totalcount=0;

    //4.0 調用bll層的分頁方法

    List<表實體> list =  bll.GetDataListByPage(ipageIndex,ipageSize,out totalcount);

    --在這裡有一個問題,我肯定要返回list給前端,但是還要返回totalcount這個總行數,還是返回totalcount/pagesize=總頁數,這我就說不定了,這是就要開始

    --研究我們的分頁控制項了。

舉例:jPageinate 分頁控制項

分頁控制項的使用,看下編文章

 

 

 

 

 

 

 

 

 

 

 

 

 

}

 

分頁之C#封裝預存程序

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.