用个GirdView不是就很简单吗?
用个GirdView不是就很简单吗?
GirdView太傻瓜了
做不出来多样式的分页。。
我不喜欢在前台用。。
这个datatable最减少系统资源.只返回当前页的数据。
Public Function ExecuteDataTableCommonProc(ByVal tablename As String, ByVal fields As String, ByVal condition As String, ByVal pagesize As Integer, ByVal currentpage As Integer, ByVal orderfield As String, ByVal ordertype As String) As DataTable
Dim textArray1 As String()
Dim text1 As String = ""
If (ordertype Is "Desc") Then
If (condition Is "None") Then
If (currentpage = 1) Then
text1 = String.Concat(New String() { "Select Top ", pagesize.ToString, " ", fields, " From ", tablename, " Order By ", orderfield, " Desc" })
Else
textArray1 = New String() { "Select Top ", pagesize.ToString, " ", fields, " From ", tablename, " Where ", orderfield, "<(Select Min(", orderfield, ") From (Select Top ", (pagesize * (currentpage - 1)).ToString, " ", orderfield, " From ", tablename, " Order By ", orderfield, " Desc) Temp) Order By ", orderfield, " Desc" }
text1 = String.Concat(textArray1)
End If
ElseIf (currentpage = 1) Then
text1 = String.Concat(New String() { "Select Top ", pagesize.ToString, " ", fields, " From ", tablename, " ", condition, " Order By ", orderfield, " Desc" })
Else
textArray1 = New String() { "Select Top ", pagesize.ToString, " ", fields, " From ", tablename, " ", condition, " And ", orderfield, "<(Select Min(", orderfield, ") From (Select Top ", (pagesize * (currentpage - 1)).ToString, " ", orderfield, " From ", tablename, " ", condition, " Order By ", orderfield, " Desc) Temp) Order By ", orderfield, " Desc" }
text1 = String.Concat(textArray1)
End If
ElseIf (condition Is "None") Then
If (currentpage = 1) Then
text1 = String.Concat(New String() { "Select Top ", pagesize.ToString, " ", fields, " From ", tablename, " Order By ", orderfield, " Asc" })
Else
textArray1 = New String() { "Select Top ", pagesize.ToString, " ", fields, " From ", tablename, " Where ", orderfield, ">(Select Max(", orderfield, ") From (Select Top ", (pagesize * (currentpage - 1)).ToString, " ", orderfield, " From ", tablename, " Order By ", orderfield, " Asc) Temp) Order By ", orderfield, " Asc" }
text1 = String.Concat(textArray1)
End If
ElseIf (currentpage = 1) Then
text1 = String.Concat(New String() { "Select Top ", pagesize.ToString, " ", fields, " From ", tablename, " ", condition, " Order By ", orderfield, " Asc" })
Else
textArray1 = New String() { "Select Top ", pagesize.ToString, " ", fields, " From ", tablename, " ", condition, " And ", orderfield, ">(Select Max(", orderfield, ") From (Select Top ", (pagesize * (currentpage - 1)).ToString, " ", orderfield, " From ", tablename, " ", condition, " Order By ", orderfield, " Asc) Temp) Order By ", orderfield, " Asc" }
text1 = String.Concat(textArray1)
End If
Return Me.ExecuteDataTable(text1)
End Function
生成分页导航
Public Shared Function GetPage(ByVal QueryString As String, ByVal Count As Integer, ByVal PageSize As Integer, ByVal CurrentPage As Integer, ByVal SizePerPage As Integer, ByVal StylePath As String) As String
Dim num1 As Integer
Dim num2 As Integer
If ((Count Mod PageSize) = 0) Then
num2 = Convert.ToInt32(CInt((Count / PageSize)))
Else
num2 = (Convert.ToInt32(CInt((Count / PageSize))) + 1)
End If
If (Not QueryString.Trim Is String.Empty) Then
QueryString = (QueryString & "&")
End If
If (num2 <= 0) Then
num2 = 1
End If
If (CurrentPage > num2) Then
CurrentPage = num2
End If
Dim builder1 As New StringBuilder
builder1.Append("<table class=Pager_Table cellspacing=1 cellpadding=0><tr>")
builder1.Append(String.Concat(New String() { "<td class=Pager_ColorTD>", Count.ToString, "</td><td class=Pager_ColorTD>", CurrentPage.ToString, "/", num2.ToString, "</td>" }))
builder1.Append(String.Concat(New String() { "<td class=Pager_TD><a href=?", QueryString, "Page=1><img src=", StylePath, "/dot_left-01.gif alt=" & ChrW(39318) & ChrW(39029) & " border=0/></a></td>" }))
If (num2 > SizePerPage) Then
Dim textArray1 As String()
If (CurrentPage > (SizePerPage / 2)) Then
If (CurrentPage > (num2 - (SizePerPage / 2))) Then
textArray1 = New String() { "<td class=Pager_TD><a href=?", QueryString, "Page=", (CurrentPage - SizePerPage).ToString, "><img src=", StylePath, "/dot_left.gif alt=" & ChrW(19978) & "10" & ChrW(39029) & " border=0/></a></td>" }
builder1.Append(String.Concat(textArray1))
num1 = (num2 - SizePerPage)
Do While (num1 <= num2)
If (num1 = CurrentPage) Then
builder1.Append(("<td class=Pager_TD><a href=# class=Red_Link>" & num1.ToString & "</a></td>"))
Else
builder1.Append(String.Concat(New String() { "<td class=Pager_TD><a href=?", QueryString, "Page=", num1.ToString, ">", num1.ToString, "</a></td>" }))
End If
num1 += 1
Loop
Else
textArray1 = New String() { "<td class=Pager_TD><a href=?", QueryString, "Page=", (CurrentPage - SizePerPage).ToString, "><img src=", StylePath, "/dot_left.gif alt=" & ChrW(19978) & "10" & ChrW(39029) & " border=0/></a></td>" }
builder1.Append(String.Concat(textArray1))
num1 = (CurrentPage - (SizePerPage / 2))
Do While (num1 <= (CurrentPage + (SizePerPage / 2)))
If (num1 = CurrentPage) Then
builder1.Append(("<td class=Pager_TD><a href=# class=Red_Link>" & num1.ToString & "</a></td>"))
Else
builder1.Append(String.Concat(New String() { "<td class=Pager_TD><a href=?", QueryString, "Page=", num1.ToString, ">", num1.ToString, "</a></td>" }))
End If
num1 += 1
Loop
textArray1 = New String(7 - 1) {}
textArray1(0) = "<td class=Pager_TD><a href=?"
textArray1(1) = QueryString
textArray1(2) = "Page="
textArray1(3) = (CurrentPage + SizePerPage).ToString
textArray1(4) = "><img src="
textArray1(5) = StylePath
textArray1(6) = "/dot_right.gif alt=" & ChrW(19979) & "10" & ChrW(39029) & " border=0/></a></td>"
builder1.Append(String.Concat(textArray1))
End If
Else
num1 = 1
Do While (num1 <= SizePerPage)
If (num1 = CurrentPage) Then
builder1.Append(("<td class=Pager_TD><a href=# class=Red_Link>" & num1.ToString & "</a></td>"))
Else
builder1.Append(String.Concat(New String() { "<td class=Pager_TD><a href=?", QueryString, "Page=", num1.ToString, ">", num1.ToString, "</a></td>" }))
End If
num1 += 1
Loop
textArray1 = New String() { "<td class=Pager_TD><a href=?", QueryString, "Page=", (CurrentPage + SizePerPage).ToString, "><img src=", StylePath, "/dot_right.gif alt=" & ChrW(19979) & "10" & ChrW(39029) & " border=0/></a></td>" }
builder1.Append(String.Concat(textArray1))
End If
Else
num1 = 1
Do While (num1 <= num2)
If (num1 = CurrentPage) Then
builder1.Append(("<td class=Pager_TD><a href=# class=Red_Link>" & num1.ToString & "</a></td>"))
Else
builder1.Append(String.Concat(New String() { "<td class=Pager_TD><a href=?", QueryString, "Page=", num1.ToString, ">", num1.ToString, "</a></td>" }))
End If
num1 += 1
Loop
End If
builder1.Append(String.Concat(New String() { "<td class=Pager_TD><a href=?", QueryString, "Page=", num2.ToString, "><img src=", StylePath, "/dot_right-01.gif alt=" & ChrW(23614) & ChrW(39029) & " border=0/></a></td></tr></table>" }))
Return builder1.ToString
End Function