Asp.net學習筆記之AspNetPager篇

來源:互聯網
上載者:User

本人學慣用asp.net做網站時間並不長,在學習過程中,分頁成為一個很大的問題,asp.net自己的組件分布的視覺效果總覺的差的很多,而且使用起來並不是很順手(也許是我技術太差了),所以我選擇在網上找專門的分頁組件,這裡選用了AspNetPager,這個一位陝西的程式員開發並封裝成Dll檔案,這個分頁組件使用起來很方便,並整合了預存程序產生工具,對我這個新手來說很有協助的.儘管這個組件使用很簡單,不過如果新手開始用這個組件的話可能還是要花上一定時間(我花了半天),現我向大家詳細介紹這個組件的使用方法:

一、用到的組件參數

RecordCount 總記錄數

StartRecordIndex 開始記錄編號(用於預存程序中)

EndRecordIndex結束記錄編號(用於預存程序中)

二、使用方法

在Page_Load中使用。

例:

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

{

    DataOperation mydo = new DataOperation();

if (!IsPostBack) //如果不是回傳就執行,用於初始化

        {

            DataOperation mydo1 = new DataOperation(); //執行個體化資料庫連接

            string sqlstr1 = "exec fy 0,0,1"; //定義Sql語句,使用了fy儲存函數

          

//初始化RecordCount,mydo1.GetExeSqlCount返回一個int

AspNetPager1.RecordCount = mydo1.GetExeSqlCount(sqlstr1);

           

//定義Sql語句,使用了fy儲存函數

string sqlstr = "exec fy " + AspNetPager1.StartRecordIndex + "," + AspNetPager1.EndRecordIndex + ",0";

           

        //給GridView1指定一資料來源, mydo.GetExeSqlDataTable返回一個DataTable

this.GridView1.DataSource = mydo.GetExeSqlDataTable(sqlstr);

           this.GridView1.DataBind();

     }

    protected void AspNetPager1_ PageChanged (object sender, EventArgs e)

    {// AspNetPager1組件的PageChanged事件

        string sqlstr = "exec fy " + AspNetPager1.StartRecordIndex + "," + AspNetPager1.EndRecordIndex + ",0";

        this.GridView1.DataSource = mydo.GetExeSqlDataTable(sqlstr);

        this.GridView1.DataBind();

    }

}

這個組件中還有很多其他的功能,大家在使用過程就會發現,設定是可視化的,這裡我就不多說了,下面是本文中用到的預存程序,相信對大家理解上面的代碼有一定協助,本文中也一起附上。

預存程序:

ALTER procedure fy

(@startIndex int,

@endIndex int,

@docount int)

as

set nocount on

if(@docount=1)

select count(*) from Xt_Article

else

begin

declare @indextable table(id int identity(1,1),nid int)

set rowcount @endIndex

insert into @indextable(nid) select id from Xt_Article order by id asc

select * from Xt_Article O,@indextable t where O.id=t.nid

and t.id between @startIndex and @endIndex order by t.id

end

set nocount off

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.