ASP data island operations

Source: Internet
Author: User

<%
'''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''
'Programming By smartpig'
'''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''
Class TBGrid
Public DataSource 'data Source
Public style 'total Table style
Public headstyle' Header style
Public HeadItemStyle 'separate Header style
Public itemStyle 'cell independent network
Public HeadSort 'whether the table header displays the sorting Function
Public Columns 'column elements to be displayed
Public Alternate: whether the style is alternating
Public AlternateStyle 'even row style'
Public normalstyle' normal style
Public DefaultStyle 'default style Cluster
Public PageSize 'page size
Public AllowPageing
Public PageingStyle

Private templates' custom unit items
Private curpage' current page
Private pagestart' page Start Time

'Relationship between content
'Columns. add "Field", "HeadText"
'Addtemplate ("HeadText", Template)
'Itemstyle. add "Field", "style: adsasd"
'Headsort. add "Field", True
'Datasource (Columns. Keys (I ))

Private Sub Class_Initialize 'sets the Initialize event.
Set itemStyle = CreateObject ("Scripting. Dictionary ")
Set HeadSort = CreateObject ("Scripting. Dictionary ")
Set HeadItemStyle = CreateObject ("Scripting. Dictionary ")
Set Columns = CreateObject ("Scripting. Dictionary ")
Set Templates = CreateObject ("Scripting. Dictionary ")
Set DataSource = CreateObject ("ADODB. Recordset ")
Alternate = 0
PageStart = Timer
End Sub

Private Sub Class_Terminate 'sets the Terminate event.
Set itemStyle = Nothing
Set HeadSort = Nothing
Set HeadItemStyle = Nothing
Set Columns = Nothing
Set DataSource = Nothing
End Sub

Private Sub InitTable ()
'Set FieldsNum = DataSource. Fields. Count
'Set RowsNum = DataSource. RecordCount
If Columns. Count = 0 then
For I = 0 to DataSource. Fields. Count-1
Columns. add DataSource. Fields (I). Name, DataSource. Fields (I). Name
Response. Write (DataSource. Fields (I). Name)
Next
End if

If IsEmpty (Style) and IsEmpty (NormalStyle) then
DefaultStyle = 1
Else
DefaultStyle = Style
End if

CurPage = CInt (Request. QueryString ("page "))
If CurPage = "" then
CurPage = 1
End If

If PageSize = Empty then
PageSize = 10
End if

Select Case DefaultStyle
Case 1
Style = "align = center border = 0 cellpadding = 4 cellspacing = 1 bgcolor = '# cccccc '"
Alternate = 1
HeadStyle = "Height = 25 style =" "background-color: #006699; color: # ffffff """
AlternateStyle = "bgColor = # ffffff height = 25"
NormalStyle = "height = 25 bgcolor = # f5f5f5"
AllowPageing = true
TbGrid1.PageingStyle = "bgcolor = '# f5f5f5 'align = 'right '"
Case 2
Style = "align = center border = 0 cellpadding = 4 cellspacing = 1 bgcolor = '# cccccc '"
Alternate = 0
HeadStyle = "Height = 25 style =" "background-color: # ffffff """
AlternateStyle = "bgColor = # ffffff height = 25"
NormalStyle = "height = 25 bgcolor = # ffffff"
Case Else
End Select
End sub

Public Sub AddTemplate (ByVal ColumnName, ByVal Template)
Columns. add ColumnName, ColumnName
Templates. add ColumnName, Template
End Sub

Public Sub Show ()
InitTable ()
Dim tableStr
Dim tdStart, tdEnd, tbStyle, tbContent
Dim curRow
Dim clm
Dim regEx, Match, Matches
TableStr = "<table" & style & ">" & vbCrLF
'Draw Table Head
Response. Write (tableStr)
Response. Write ("<tr> ")
For Each clm in Columns. Keys ()
TbStyle = HeadStyle & "" & HeadItemStyle (clm)
TdStart = "<th" & tbStyle & ">"
TdEnd = "</th>" & vbCrLf

Response. Write (tdStart)
'Add the table header sorting Function
'Code by Redsun
'Date: 2005-1-17
If HeadSort (clm) Then
Response. Write Sort (clm, Columns (clm ))
Else
Response. Write (Columns (clm ))
End If
Response. Write (tdEnd)
Next
Response. Write ("</tr>" & vbCrLF)

'Draw Table items
CurRow = 1
If AllowPageing <> Empty then
DataSource. PageSize = PageSize
Else
DataSource. PageSize = DataSource. RecordCount
End if

If CurPage <1 then
DataSource. AbsolutePage = 1
End if

If CurPage> = DataSource. PageCount then
DataSource. AbsolutePage = DataSource. PageCount
End if

If CurPage> = 1 and CurPage <= DataSource. PageCount then
DataSource. AbsolutePage = CurPage
End if

For curRow = 1 to DataSource. PageSize
If DataSource. EOF then
Exit
End if

Response. Write ("<tr> ")
For Each clm in Columns. Keys ()
If Alternate = 0 then
TbStyle = NormalStyle & "" & ItemStyle (clm)
Else
If curRow mod 2 = 0 then
TbStyle = AlternateStyle & "& ItemStyle (clm)
Else
TbStyle = NormalStyle & "" & ItemStyle (clm)
End if
End if

TdStart = "<td" & tbStyle & ">"
TdEnd = "</td>" & vbCrLf

If Templates (clm) = Empty then
TbContent = DataSource (clm)
Else
TbContent = Templates (clm)
Set regEx = New RegExp
RegEx. Pattern = "{[A-Za-z0-9 _-] + }"
RegEx. IgnoreCase = True
RegEx. Global = True
Set Matches = regEx. Execute (Templates (clm ))
For each match in matches
On Error Resume Next
TbContent = Replace (tbContent, Match. Value, DataSource (Mid (Match. Value, 2, Len (Match. Value)-2), 1)
Next

End if

Response. Write (tdStart)
Response. Write (tbContent)
Response. Write (tdEnd)
Next
Response. Write ("</tr>" & vbCrLF)

DataSource. MoveNext
Next

'Draw Pageing Row
If DataSource. PageCount> 1 and LCase (pageingStyle) <> "none" then
Dim I, EndPage, StartPage
Response. write ("<tr> ")
Response. write ("<td colspan =" & Columns. Count & "" & PageingStyle & "> ")
'Improves the paging function.
'Code by Redsun
'Date: 2005-1-17
If CurPage> 4 Then
If CurPage + 2 <DataSource. PageCount Then
StartPage = CurPage-2
EndPage = CurPage + 2
Else
StartPage = DataSource. PageCount-4
EndPage = DataSource. PageCount
End If
Else
StartPage = 1
If DataSource. PageCount> 5 Then
EndPage = 5
Else
EndPage = DataSource. PageCount
End If
End If
If CurPage> 1 Then
Response. write "<a title = 'homepage' href = '" & GetUrl ("page ") & "page = 1'> <font face = webdings> 9 </font> </a>"
Response. write "<a title = 'previous page' href = '" & GetUrl ("page ") & "page =" & CurPage-1 & "'> <font face = webdings> 3 </font> </a>"
Else
Response. Write "<font face = webdings> 9 </font>"
Response. Write "<font face = webdings> 3 </font>"
End If
For I = StartPage to EndPage
If I <> CurPage then
Response. write ("<a title = '" & I & "page 'href ='" & GetUrl ("page ") & "page =" & I & "'>" & I & "</a> ")
Else
Response. write ("<B>" & I & "</B> ")
End if
Next
If CurPage <DataSource. PageCount Then
Response. write "<a title = 'Next page' href = '" & GetUrl ("& page &") & "page =" & CurPage + 1 & "'> <font face = webdings> 4 </font> </a>"
Response. write "<a title = 'tail' href = '" & GetUrl ("& page &") & "page =" & DataSource. pageCount & "'> <font face = webdings >:</font> </a>"
Else
Response. Write "<font face = webdings> 4 </font>"
Response. Write "<font face = webdings >:</font>"
End If
Response. Write "[total" & DataSource. RecordCount & "bar] [" & PageSize & "bar/Page] [total" & DataSource. PageCount & "Page]"
Response. Write "PageExecute:" & Round (Timer-PageStart) * 1000,2) & "MS"
Response. write ("</td> </tr>" & vbCrLf)
End if
'Draw Table end
Response. Write ("</table> ")
End sub

'================================================ ==================================
'Obtain the function of the current Url parameter
'Codeing by Redsun
'================================================ ==================================
Private Function GetUrl (RemoveList)
Dim ScriptAddress, M_ItemUrl, M_item
ScriptAddress = CStr (Request. ServerVariables ("SCRIPT_NAME "))&"? "'Get the current address
M_ItemUrl = ""
For Each M_item In Request. QueryString
If InStr (RemoveList, M_Item) = 0 Then
M_ItemUrl = M_ItemUrl & M_Item & "=" & Server. URLEncode (Request. QueryString ("" & M_Item &""))&"&"
End If
Next
GetUrl = ScriptAddress & M_ItemUrl
End Function

'==================================
'Sort the list.
'Return Url parameters and dynamically change the sorting method
'Parameter: the name of the field to be sorted.
'==================================
Private Function Sort (SortStr, DispName)
If SortStr = "" Or DispName = "" Then Exit Function
Sort = GetUrl ("SOrder, SSort ")
SSort = UCase (Request. QueryString ("SSort "))
If SSort = "DESC" Then
SSort = "ASC"
Else
SSort = "DESC"
End If
Sort = "<a class = 'headhref 'href = '" & Sort & "SOrder =" & SortStr & "& SSort =" & SSort & "'>" & DispName & SortType (SortStr) & "</a>"
End Function

'-----------------------------------------------
'Indicates whether the sorting column is in ascending or descending order
'Parameter: name of the sorting column Field
'-----------------------------------------------
Private Function SortType (FieldName)
Dim SOrderName
SOrderName = Request. QueryString ("SOrder ")
If SOrderName <> FieldName Then Exit Function
Dim SSortImg
SSortImg = Request. QueryString ("SSort ")
SortType = "End Function

End Class

'Users Like {UserID, LoginName, Password, RealName, Age, Gender ,}
'Initdb
Rs. Open "Select * from users", Cn
Dim tbGrid1
Set tbGrid1 = New TBGrid
Set tbGrid1.DataSource = Rs
TbGrid1.Columns. add "LoginName", "User Name"
TbGrid1.HeadSort. add "LoginName", True
TbGrid1.Columns. add "Password", "Password"
TbGrid1.AddTemplate "modify", "<a href = 'aaa. asp? Id = {UserID} '> <font color = red> {RealName} </font> </a>"
TbGrid1.ItemStyle. add "Password", "align = right"
TbGrid1.ItemStyle. add "modify", "width = 100"
TbGrid1.PageSize = 5
TbGrid1.AllowPageing = true
TbGrid1.PageingStyle = "align = right"
TbGrid1.Show ()
'Closedb
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.