自定義GridView分頁模板

2021-04-12 20:03:43 字數 1109 閱讀 9908

gridview較之datagrid提供了更加強大、更加完善的功能,而且具備了豐富的可擴充套件功能,可以使用gridview提供的pagertemplate自定義分頁模板:

事實上,gridview預設的幾中分頁樣式,都是將相關按鈕的commandname設為page,而commandargument設為相關引數,可接受的引數包括,first,last,prev,next,(具體數字),然後按事件回溯,觸發頂層的rowcommand,因此我們頁可以使用這些預設的可識別的引數自定義自己的分頁模板,asp.net會自動設定當前的newpageindex,而不需要任何的冗餘**。

.aspx頁面:

pageindexchanging處理程式:

protected void gridview1_pageindexchanging(object sender, gridviewpageeventargs e)

if (null != txtnewpageindex)

}else

// check to prevent form the newpageindex out of the range

newpageindex = newpageindex < 0 ? 0 : newpageindex;

newpageindex = newpageindex >= thegrid.pagecount ? thegrid.pagecount - 1 : newpageindex;

// specify the newpageindex

thegrid.pageindex = newpageindex;

// rebind the control

// in this case of retrieving the data using the ***datasoucr control,

// just do nothing, because the asp.net engine binds the data automatically

}注意到,上面的示例中,由於增加了乙個跳轉按鈕go,但是asp。net不支援相關的commandargument值,雖然可以將go button的commandname設為page,還需要手動的在pageindexchanging增加部分處理邏輯。

GridView自定義分頁

在 asp.net 2.0 種提供了 gridview 控制項。該控制項的分頁比較方便,可以通過在 visual studio net 2005 種簡單設定即可實現各種分頁功能。1.預設分頁方式 1 是否允許分頁 gridview 的allowpaging 屬性。2 每頁記錄數 gridview 的...

gridview 自定義分頁

總記錄數 private int totalcountrecord 每頁顯示的條數 private int pageitem 5 當前頁 private int currentpage 1 private string strurl string.empty protected void page ...

GridView自定義分頁

該控制項的分頁比較方便,可以通過在visual studio net 2005種簡單設定即可實現各種分頁功能。1.預設分頁方式 1 是否允許分頁 gridview的allowpaging屬性。2 每頁記錄數 gridview的 pagesize 3 分頁導航條形式 gridview的 pagerse...