您目前尚未登陆,请选择【登陆】或【注册
首页->全站代码->DotNetNuke04.08.03免安装版项目源码>>Library/Controls/PagingControl.vb>>代码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:DotNetNuke04.08.03免安装版项目源码


当前文件路径:DNN/Library/Controls/PagingControl.vb 文件类型
普通视图
		            
1' 2' DotNetNuke?- http://www.dotnetnuke.com 3' Copyright (c) 2002-2008 4' by DotNetNuke Corporation 5' 6' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 7' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 8' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 9' to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10' 11' The above copyright notice and this permission notice shall be included in all copies or substantial portions 12' of the Software. 13' 14' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 15' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 17' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18' DEALINGS IN THE SOFTWARE. 19' 20 21Imports System.ComponentModel 22Imports System.Web.UI 23Imports DotNetNuke 24 25 26Namespace DotNetNuke.UI.WebControls 27 28 29 <ToolboxData("<{0}:PagingControl runat=server></{0}:PagingControl>")> Public Class PagingControl 30 Inherits System.Web.UI.WebControls.WebControl 31 32 Protected tablePageNumbers As System.Web.UI.WebControls.Table 33 Protected WithEvents PageNumbers As System.Web.UI.WebControls.Repeater 34 Protected cellDisplayStatus As System.Web.UI.WebControls.TableCell 35 Protected cellDisplayLinks As System.Web.UI.WebControls.TableCell 36 37 Private TotalPages As Integer = -1 38 39 Private _TotalRecords As Integer 40 Private _PageSize As Integer 41 Private _CurrentPage As Integer 42 Private _QuerystringParams As String 43 Private _TabID As Integer 44 Private _CSSClassLinkActive As String 45 Private _CSSClassLinkInactive As String 46 Private _CSSClassPagingStatus As String 47 48 <Bindable(True), Category("Behavior"), DefaultValue("0")> Property TotalRecords() As Integer 49 Get 50 Return _TotalRecords 51 End Get 52 53 Set(ByVal Value As Integer) 54 _TotalRecords = Value 55 End Set 56 End Property 57 <Bindable(True), Category("Behavior"), DefaultValue("10")> Property PageSize() As Integer 58 Get 59 Return _PageSize 60 End Get 61 62 Set(ByVal Value As Integer) 63 _PageSize = Value 64 End Set 65 End Property 66 <Bindable(True), Category("Behavior"), DefaultValue("1")> Property CurrentPage() As Integer 67 Get 68 Return _CurrentPage 69 End Get 70 71 Set(ByVal Value As Integer) 72 _CurrentPage = Value 73 End Set 74 End Property 75 <Bindable(True), Category("Behavior"), DefaultValue("")> Property QuerystringParams() As String 76 Get 77 Return _QuerystringParams 78 End Get 79 80 Set(ByVal Value As String) 81 _QuerystringParams = Value 82 End Set 83 End Property 84 <Bindable(True), Category("Behavior"), DefaultValue("-1")> Property TabID() As Integer 85 Get 86 Return _TabID 87 End Get 88 89 Set(ByVal Value As Integer) 90 _TabID = Value 91 End Set 92 End Property 93 <Bindable(True), Category("Behavior"), DefaultValue("Normal")> Property CSSClassLinkActive() As String 94 Get 95 If _CSSClassLinkActive = "" Then 96 Return "CommandButton" 97 Else 98 Return _CSSClassLinkActive 99 End If 100 End Get 101 102 Set(ByVal Value As String) 103 _CSSClassLinkActive = Value 104 End Set 105 End Property 106 <Bindable(True), Category("Behavior"), DefaultValue("CommandButton")> Property CSSClassLinkInactive() As String 107 Get 108 If _CSSClassLinkInactive = "" Then 109 Return "NormalDisabled" 110 Else 111 Return _CSSClassLinkInactive 112 End If 113 End Get 114 115 Set(ByVal Value As String) 116 _CSSClassLinkInactive = Value 117 End Set 118 End Property 119 <Bindable(True), Category("Behavior"), DefaultValue("Normal")> Property CSSClassPagingStatus() As String 120 Get 121 If _CSSClassPagingStatus = "" Then 122 Return "Normal" 123 Else 124 Return _CSSClassPagingStatus 125 End If 126 End Get 127 128 Set(ByVal Value As String) 129 _CSSClassPagingStatus = Value 130 End Set 131 End Property 132 133 Protected Overrides Sub CreateChildControls() 134 tablePageNumbers = New System.Web.UI.WebControls.Table 135 cellDisplayStatus = New System.Web.UI.WebControls.TableCell 136 cellDisplayLinks = New System.Web.UI.WebControls.TableCell 137 cellDisplayStatus.CssClass = "Normal" 138 cellDisplayLinks.CssClass = "Normal" 139 140 If Me.CssClass = "" Then 141 tablePageNumbers.CssClass = "PagingTable" 142 Else 143 tablePageNumbers.CssClass = Me.CssClass 144 End If 145 146 Dim intRowIndex As Integer = tablePageNumbers.Rows.Add(New TableRow) 147 148 PageNumbers = New Repeater 149 Dim I As New PageNumberLinkTemplate(Me) 150 PageNumbers.ItemTemplate = I 151 BindPageNumbers(TotalRecords, PageSize) 152 153 cellDisplayStatus.HorizontalAlign = HorizontalAlign.Left 154 cellDisplayStatus.Width = New Unit("50%") 155 cellDisplayLinks.HorizontalAlign = HorizontalAlign.Right 156 cellDisplayLinks.Width = New Unit("50%") 157 Dim intTotalPages As Integer = TotalPages 158 If intTotalPages = 0 Then intTotalPages = 1 159 160 Dim str As String 161 str = String.Format(Services.Localization.Localization.GetString("Pages"), CurrentPage.ToString, intTotalPages.ToString) 162 Dim lit As New LiteralControl(str) 163 cellDisplayStatus.Controls.Add(lit) 164 165 tablePageNumbers.Rows(intRowIndex).Cells.Add(cellDisplayStatus) 166 tablePageNumbers.Rows(intRowIndex).Cells.Add(cellDisplayLinks) 167 168 End Sub 169 170 Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter) 171 If PageNumbers Is Nothing Then 172 CreateChildControls() 173 End If 174 175 Dim str As New System.Text.StringBuilder 176 177 str.Append(GetFirstLink() + "&nbsp;&nbsp;&nbsp;") 178 str.Append(GetPreviousLink() + "&nbsp;&nbsp;&nbsp;") 179 Dim result As System.Text.StringBuilder = New System.Text.StringBuilder(1024) 180 PageNumbers.RenderControl(New HtmlTextWriter(New System.IO.StringWriter(result))) 181 str.Append(result.ToString()) 182 str.Append(GetNextLink() + "&nbsp;&nbsp;&nbsp;") 183 str.Append(GetLastLink() + "&nbsp;&nbsp;&nbsp;") 184 cellDisplayLinks.Controls.Add(New LiteralControl(str.ToString)) 185 186 tablePageNumbers.RenderControl(output) 187 188 End Sub 189 190 191 Private Sub BindPageNumbers(ByVal TotalRecords As Integer, ByVal RecordsPerPage As Integer) 192 Dim PageLinksPerPage As Integer = 10 193 If TotalRecords / RecordsPerPage >= 1 Then 194 TotalPages = Convert.ToInt32(Math.Ceiling(CType(TotalRecords / RecordsPerPage, Double))) 195 Else 196 TotalPages = 0 197 End If 198 199 If TotalPages > 0 Then 200 Dim ht As New DataTable 201 ht.Columns.Add("PageNum") 202 Dim tmpRow As DataRow 203 204 Dim LowNum As Integer = 1 205 Dim HighNum As Integer = CType(TotalPages, Integer) 206 207 Dim tmpNum As Double 208 tmpNum = CurrentPage - PageLinksPerPage / 2 209 If tmpNum < 1 Then tmpNum = 1 210 211 If CurrentPage > (PageLinksPerPage / 2) Then 212 LowNum = CType(Math.Floor(tmpNum), Integer) 213 End If 214 215 If CType(TotalPages, Integer) <= PageLinksPerPage Then 216 HighNum = CType(TotalPages, Integer) 217 Else 218 HighNum = LowNum + PageLinksPerPage - 1 219 End If 220 221 If HighNum > CType(TotalPages, Integer) Then 222 HighNum = CType(TotalPages, Integer) 223 If HighNum - LowNum < PageLinksPerPage Then 224 LowNum = HighNum - PageLinksPerPage + 1 225 End If 226 End If 227 228 If HighNum > CType(TotalPages, Integer) Then HighNum = CType(TotalPages, Integer) 229 If LowNum < 1 Then LowNum = 1 230 231 Dim i As Integer 232 For i = LowNum To HighNum 233 tmpRow = ht.NewRow 234 tmpRow("PageNum") = i 235 ht.Rows.Add(tmpRow) 236 Next 237 238 PageNumbers.DataSource = ht 239 PageNumbers.DataBind() 240 End If 241 242 End Sub 243 244 Private Function CreateURL(ByVal CurrentPage As String) As String 245 246 If QuerystringParams <> "" Then 247 If CurrentPage <> "" Then 248 Return Common.Globals.NavigateURL(TabID, "", QuerystringParams, "currentpage=" & CurrentPage) 249 Else 250 Return Common.Globals.NavigateURL(TabID, "", QuerystringParams) 251 End If 252 Else 253 If CurrentPage <> "" Then 254 Return Common.Globals.NavigateURL(TabID, "", "currentpage=" & CurrentPage) 255 Else 256 Return Common.Globals.NavigateURL(TabID) 257 End If 258 End If 259 260 End Function 261 262 ''' ----------------------------------------------------------------------------- 263 ''' <summary> 264 ''' GetLink returns the page number links for paging. 265 ''' </summary> 266 ''' <remarks> 267 ''' </remarks> 268 ''' <history> 269 ''' [dancaron] 10/28/2004 Initial Version 270 ''' </history> 271 ''' ----------------------------------------------------------------------------- 272 Private Function GetLink(ByVal PageNum As Integer) As String 273 If PageNum = CurrentPage Then 274 Return "<span class=""" + CSSClassLinkInactive + """>[" + PageNum.ToString + "]</span>" 275 Else 276 Return "<a href=""" + CreateURL(PageNum.ToString) + """ class=""" + CSSClassLinkActive + """>" + PageNum.ToString + "</a>" 277 End If 278 End Function 279 280 ''' ----------------------------------------------------------------------------- 281 ''' <summary> 282 ''' GetPreviousLink returns the link for the Previous page for paging. 283 ''' </summary> 284 ''' <remarks> 285 ''' </remarks> 286 ''' <history> 287 ''' [dancaron] 10/28/2004 Initial Version 288 ''' </history> 289 ''' ----------------------------------------------------------------------------- 290 Private Function GetPreviousLink() As String 291 If CurrentPage > 1 AndAlso TotalPages > 0 Then 292 Return "<a href=""" + CreateURL((CurrentPage - 1).ToString) + """ class=""" + CSSClassLinkActive + """>" & Services.Localization.Localization.GetString("Previous", DotNetNuke.Services.Localization.Localization.SharedResourceFile) & "</a>" 293 Else 294 Return "<span class=""" + CSSClassLinkInactive + """>" & Services.Localization.Localization.GetString("Previous", DotNetNuke.Services.Localization.Localization.SharedResourceFile) & "</span>" 295 End If 296 End Function 297 298 ''' ----------------------------------------------------------------------------- 299