SoFunction
Updated on 2025-04-09

ASP data island operation category

<%
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'            Programming By Smartpig                              '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Class TBGrid
public DataSource
public style                                                                                                                                                                                                                                                             �
public HeadStyle                           'HeadStyle
public HeadItemStyle              'The header is individually styled
public itemStyle                                                           �
public HeadSort     'Does the header display the sorting function
public Columns
public Alternate                                                                                                                                                                                                                                                            �
public AlternateStyle           'Even-numbered line style
public NormalStyle
public DefaultStyle             'Default Style Cluster
public PageSize
public AllowPageing               'Is it paging
public PageingStyle             'Page Number Style

Private Templates 'Custom unit items
private CurPage
private PageStart    'Page start running time

'The relationship between contents
    ' "Field","HeadText"
    'AddTemplate("HeadText",Template)
    ' "Field","style:adsasd"
    ' "Field",True
    'DataSource((i))

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

Private Sub Class_Terminate   'Set 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    = 
        'Set RowsNum     = 
        if  = 0 then
            For i = 0 to  -1
                 (i).Name,(i).Name
                ((i).Name)
            Next
        end if

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

        CurPage = CInt(("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
             = "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)
         ColumnName,ColumnName
         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
        (tableStr)
        ("<tr>")
        for Each clm in ()
            tbStyle = HeadStyle & " " & HeadItemStyle(clm)
            tdStart = "<th "&tbStyle&">"
            tdEnd = "</th>" & vbCrLf

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

        'Draw Table items
        curRow = 1
        if AllowPageing <> Empty then
             = PageSize
        else
             = 
        end if

        if CurPage < 1 then
             = 1
        end if

        if CurPage >=  then
             = 
        end if

        if CurPage >= 1 and CurPage <=  then
             = CurPage
        end if

        for curRow = 1 to 
            if  then
                Exit For
            end if

            ("<tr>")
            for Each clm in ()
                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
                    = "{[A-Za-z0-9_-]+}"
                     = True
                     = True
                    Set Matches=(Templates(clm))
                    For each match in matches
                        On Error Resume Next
                        tbContent = Replace(tbContent,,DataSource(Mid(,2,Len()-2)),1) 
                    Next

                end if

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

            
        Next

        'Draw Pageing Row
        if  > 1 and LCase(pageingStyle) <> "none" then
            Dim i,EndPage,StartPage
            ("<tr>")
            ("<td colspan=" &  & " " & PageingStyle & ">")
'Improved paging function
            'Code by Redsun
            'Date:2005-1-17
            If CurPage>4 Then
                If CurPage+2< Then
                    StartPage = CurPage-2
                    EndPage = CurPage+2
                Else
                    StartPage = -4
                    EndPage = 
                End If
            Else
                StartPage = 1
                If >5 Then
                    EndPage = 5
                Else
                    EndPage = 
                End If
            End If
            If CurPage>1 Then
"<a title='Home' href='"&GetUrl("page")&"page=1'><font face=webdings>9</font></a> "
"<a title='Previous page' href='"&GetUrl("page")&"page="&CurPage-1&"'><font face=webdings>3</font></a> "
            Else
                 "<font face=webdings>9</font> "
                 "<font face=webdings>3</font> "
            End If 
            For i=StartPage to EndPage
                if i <> CurPage then
("<a title='Page "&i&"' href='"&GetUrl("page")&"page="&i&"'>"&i&"</a> ")
                Else
                    ("<b>"&i&"</b> ")
                End if
            next
            If CurPage< Then
"<a title='next page' href='"&GetUrl("&page&")&"page="&CurPage+1&"'><font face=webdings>4</font></a> "
"<a title='last page' href='"&GetUrl("&page&")&"page="&&"'><font face=webdings>:</font></a> "
            Else
                 "<font face=webdings>4</font> "
                 "<font face=webdings>:</font> "
            End If
"&nbsp;&nbsp;[Total"&&"bar]["&PageSize&"bar/page][[Total"&&"bar]"
             " PageExecute:"&Round((Timer-PageStart)*1000,2)&" MS"
            ("</td></tr>" & vbCrLf)
        End if
        'Draw Table end
        ("</table>")
    End sub

    '====================================================================
'The function to get the current Url parameter
    'Codeing by Redsun
    '====================================================================
    Private Function GetUrl(RemoveList)
        Dim ScriptAddress, M_ItemUrl, M_item
ScriptAddress = CStr(("SCRIPT_NAME"))&"?"'Get the current address
        M_ItemUrl = ""
        For Each M_item In 
            If InStr(RemoveList,M_Item)=0 Then
                M_ItemUrl = M_ItemUrl & M_Item &"="& ((""&M_Item&"")) & "&"
            End If
        Next
        GetUrl = ScriptAddress & M_ItemUrl
    End Function

    
    '=============================
'Implement list sorting
'Return the Url parameter and dynamically change the sorting method
'Parameter: The field name that needs to be sorted, the name that is displayed
    '=============================
    Private Function Sort(SortStr,DispName)
        If SortStr = "" Or DispName="" Then Exit Function
        Sort = GetUrl("SOrder,SSort")
        SSort = UCase(("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

    '-----------------------------------------------
'Identify the sorting column in ascending or descending order
'Parameter: sorting column field name
    '-----------------------------------------------
    Private Function SortType(FieldName)
        Dim SOrderName
        SOrderName = ("SOrder")
        If SOrderName<>FieldName Then Exit Function
        Dim SSortImg
        SSortImg = ("SSort")
        SortType = "<img src='/OrderFormSystem/images/"&SSortImg&".gif' border='0'>"
    End Function

End Class


'users Like { UserID,LoginName,Password,RealName,Age,Gender,}
'initDB
 "Select * from users",Cn
Dim tbGrid1
Set tbGrid1 = New TBGrid
Set  = Rs
"LoginName", "Username"
 "LoginName",True
"Password", "Password"
"Modify","<a href='?id={UserID}'><font color=red>{RealName}</font></a>"
 "Password","align=right"
"Modify","width=100"
 = 5
 = true
 = "align=right"
()
'CloseDB
%>