淺談VS中的DataPager分頁(yè)
微軟的DataPager分頁(yè)功能很強(qiáng)大,不要設(shè)置數(shù)據(jù)庫(kù)存儲(chǔ)過(guò)程,只要添加個(gè)DataPager控件,關(guān)聯(lián)下要分頁(yè)的控件,簡(jiǎn)單設(shè)置就可以有不錯(cuò)的分頁(yè)效果。當(dāng)然要有更理想的效果還是要前臺(tái)和后臺(tái)處理下。
winform下的DataPager 顯示模式:

webForm下的樣式由TemplatePagerField,NextPreviousPagerField和NumericPagerField控制
通過(guò)設(shè)置上面幾個(gè)控件的配合也可以達(dá)到winForm下的效果,這3個(gè)控件中最重要的是TemplatePagerField控件。
下面簡(jiǎn)單看看TemplatePagerField控件可以怎么設(shè)置:
<%@ Page language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
" <script runat="server">
Protected Sub TemplatePagerField_OnPagerCommand(ByVal sender As Object, _
ByVal e As DataPagerCommandEventArgs)
' Check which button raised the event
Select Case e.CommandName
Case "Next"
Dim newIndex As Integer = e.Item.Pager.StartRowIndex + e.Item.Pager.PageSize
If newIndex <= e.TotalRowCount Then
e.NewStartRowIndex = newIndex
e.NewMaximumRows = e.Item.Pager.MaximumRows
End If
Case "Previous"
e.NewStartRowIndex = e.Item.Pager.StartRowIndex - e.Item.Pager.PageSize
e.NewMaximumRows = e.Item.Pager.MaximumRows
Case "First"
e.NewStartRowIndex = 0
e.NewMaximumRows = e.Item.Pager.MaximumRows
End Select
End Sub
</script>
<html xmlns=" <head id="Head1" runat="server">
<title>TemplatePagerField.OnPagerCommand Example</title>
<style type="text/css">
body
{
text-align: center;
font: 12px Arial, Helvetica, sans-serif;
}
.item
{
border: solid 1px #2F4F4F;
background: #E6E6FA;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<h3>TemplatePagerField.OnPagerCommand Example</h3>
<asp:ListView ID="StoresListView"
DataSourceID="StoresDataSource"
runat="server">
<LayoutTemplate>
<table width="350" runat="server" id="tblStore">
<tr runat="server">
<th runat="server">ID</th>
<th runat="server">Store Name</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr runat="server">
<td class="item">
<asp:Label ID="IDLabel" runat="server" Text='<%#Eval("CustomerID") %>' />
</td>
<td align="left" class="item">
<asp:Label ID="NameLabel" runat="server" Text='<%#Eval("Name")%>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<br />
<asp:DataPager runat="server"
ID="ContactsDataPager"
PageSize="30"
PagedControlID="StoresListView">
<Fields>
<asp:TemplatePagerField OnPagerCommand="TemplatePagerField_OnPagerCommand">
<PagerTemplate>
<asp:LinkButton ID="FirstButton" runat="server" CommandName="First"
Text="<<" Enabled='<%# Container.StartRowIndex > 0 %>' />
<asp:LinkButton ID="PreviousButton" runat="server" CommandName="Previous"
Text='<%# (Container.StartRowIndex - Container.PageSize + 1) & " - " & (Container.StartRowIndex) %>'
Visible='<%# Container.StartRowIndex > 0 %>' />
<asp:Label ID="CurrentPageLabel" runat="server"
Text='<%# (Container.StartRowIndex + 1) & "-" & (IIf(Container.StartRowIndex + Container.PageSize > Container.TotalRowCount, Container.TotalRowCount, Container.StartRowIndex + Container.PageSize)) %>' />
<asp:LinkButton ID="NextButton" runat="server" CommandName="Next"
Text='<%# (Container.StartRowIndex + Container.PageSize + 1) & " - " & (IIf(Container.StartRowIndex + Container.PageSize*2 > Container.TotalRowCount, Container.TotalRowCount, Container.StartRowIndex + Container.PageSize*2)) %>'
Visible='<%# (Container.StartRowIndex + Container.PageSize) < Container.TotalRowCount %>' />
</PagerTemplate>
</asp:TemplatePagerField>
</Fields>
</asp:DataPager>
<asp:SqlDataSource ID="StoresDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
SelectCommand="SELECT [CustomerID], [Name] FROM Sales.Store ORDER BY [Name]">
</asp:SqlDataSource>
</form>
</body>
</html>
- asp.net中讓Repeater和GridView支持DataPager分頁(yè)
- asp.net實(shí)現(xiàn)簡(jiǎn)單分頁(yè)實(shí)例
- asp.net gridview分頁(yè):第一頁(yè) 下一頁(yè) 1 2 3 4 上一頁(yè) 最末頁(yè)
- ASP.NET MVC 5使用X.PagedList.Mvc進(jìn)行分頁(yè)教程(PagedList.Mvc)
- Asp.net GridView使用大全(分頁(yè)實(shí)現(xiàn))
- asp.net中g(shù)ridview的查詢、分頁(yè)、編輯更新、刪除的實(shí)例代碼
- Asp.Net數(shù)據(jù)控件引用AspNetPager.dll分頁(yè)實(shí)現(xiàn)代碼
- asp.net分頁(yè)控件AspNetPager的樣式美化
- ASP.NET 高性能分頁(yè)代碼
相關(guān)文章
ASP.NET中母版頁(yè)和shtml實(shí)例入門(mén)
這篇文章主要介紹了ASP.NET中母版頁(yè)和shtml,較為簡(jiǎn)單的分析了asp.net的母版頁(yè)和shtml相關(guān)用法,需要的朋友可以參考下2015-06-06
ASP.NET MVC限制同一個(gè)IP地址單位時(shí)間間隔內(nèi)的請(qǐng)求次數(shù)
這篇文章介紹了ASP.NET MVC限制同一個(gè)IP地址單位時(shí)間間隔內(nèi)請(qǐng)求次數(shù)的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-10-10
官網(wǎng) Ext direct包中.NET版的問(wèn)題
下載了官網(wǎng)的 Ext direct 包進(jìn)行研究,發(fā)現(xiàn)服務(wù)器端返回結(jié)果存在一點(diǎn)小問(wèn)題。2009-06-06
ASP.NET?使用?Dispose?釋放資源的四種方法詳細(xì)介紹
本篇文章主要介紹了ASP.NET?使用?Dispose?釋放資源的四種方法,有興趣的同學(xué)可以來(lái)看看,喜歡的話記得收藏一下哦,方便下次瀏覽觀看2021-11-11
記錄asp.net網(wǎng)站是什么原因?qū)е峦V惯\(yùn)行的代碼
這篇文章主要介紹了記錄asp.net網(wǎng)站是什么原因?qū)е峦V惯\(yùn)行的具體實(shí)現(xiàn)2014-03-03
SignalR中豐富多彩的消息推送方式的實(shí)現(xiàn)代碼
這篇文章主要介紹了SignalR中豐富多彩的消息推送方式的實(shí)現(xiàn)代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04
在ASP.NET Core中顯示自定義的錯(cuò)誤頁(yè)面
大家在用瀏覽器訪問(wèn)服務(wù)器時(shí),不同情況下會(huì)返回不同的信息。服務(wù)器發(fā)生錯(cuò)誤就會(huì)返回錯(cuò)誤信息,我們最熟悉的就是404錯(cuò)誤頁(yè)面,但是這里我想和大家分享下在ASP.NET Core中如何顯示自定義的500或404錯(cuò)誤頁(yè)面,有需要的朋友們可以參考借鑒,下面來(lái)一起看看吧。2016-12-12
.Net平臺(tái)開(kāi)發(fā)實(shí)踐的一些點(diǎn)滴總結(jié)(技術(shù)規(guī)范與實(shí)踐精華)
以下是本人對(duì).Net平臺(tái)開(kāi)發(fā)實(shí)踐的一些點(diǎn)滴總結(jié)。這里的技術(shù)規(guī)范主要是開(kāi)發(fā)過(guò)程的代碼規(guī)范、數(shù)據(jù)庫(kù)設(shè)計(jì)規(guī)范、Com和.Net互操作規(guī)范;實(shí)踐精華是對(duì)技術(shù)實(shí)踐過(guò)程中的部分總結(jié)。2010-04-04
基于ASP.NET實(shí)現(xiàn)驗(yàn)證碼生成詳解
這篇文章主要為大家詳細(xì)介紹了如何利用ASP.NET實(shí)現(xiàn)驗(yàn)證碼的生成,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03

