淺談VS中的DataPager分頁(yè)
來(lái)源:易賢網(wǎng) 閱讀:1733 次 日期:2015-02-27 10:58:43
溫馨提示:易賢網(wǎng)小編為您整理了“淺談VS中的DataPager分頁(yè)”,方便廣大網(wǎng)友查閱!

微軟的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 顯示模式:

名單

淺談VS中的DataPager分頁(yè)

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>

更多信息請(qǐng)查看IT技術(shù)專欄

更多信息請(qǐng)查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機(jī)網(wǎng)站地址:淺談VS中的DataPager分頁(yè)
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

2025國(guó)考·省考課程試聽(tīng)報(bào)名

  • 報(bào)班類型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)