Implement ASP.net's DataGrid function in ASP (reprint)

Source: Internet
Author: User
Tags count empty implement
Asp.net|datagrid since the use of the penetration. NET DataGrid will no longer bother to use ASP to draw tables, so think of a compromise approach, visit the DataGrid function wrote a Tbgrid class, so you can easily reuse code. It is more convenient to repeat the work than every time. Hope to bring some convenience to the people who use it. The use is very simple, look at the following example will be a glance. What is the imperfect place I hope you have to discuss with me.
<%
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Programming by Smartpig '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Class Tbgrid

Public DataSource ' data source
Public style ' table total style
Public Headstyle ' table head style
Public Headitemstyle ' table head individual style
Public ItemStyle ' cell Standalone network
Public Columns ' column element to display
Public alternate ' whether alternating style
Public Alternatestyle ' even line style
Public Normalstyle ' Normal style
Public DefaultStyle ' default style cluster
Public PageSize ' page size
Public Curpage ' current page
Public allowpageing ' is paging
Public Pageingstyle ' page style

Private Templates ' Custom cell items

' The relationship between content
' Columns.Add ' Field ', ' Headtext '
' Addtemplate ("Headtext", Template)
' Itemstyle.add ' Field ', ' STYLE:ADSASD '
' DataSource (Columns.keys (i))

Private Sub class_initialize ' sets Initialize event.
Set ItemStyle = 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
End Sub

Private Sub class_terminate ' sets Terminate event.
Set ItemStyle = 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
End If

If PageSize = Empty Then
PageSize = 10
End If

Select Case DefaultStyle
Case 1
Style = "Border=1 cellpadding=2 cellspaccing=0 bordercolor= #000000 style=" "border-collapse:collapse;font-size:12px" " "
Alternate = 1
Headstyle = "Height=25 bgcolor= #CCCCCC"
Alternatestyle = "bgcolor= #EEEEEE height=20"
Normalstyle = "Height=20"

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 = "<td" & Tbstyle & ">"
Tdend = "</td>"

Response.Write (Tdstart)
Response.Write (Columns (CLM))
Response.Write (Tdend)
Next
Response.Write ("</tr>" & VbCrLF)

' Draw Table items
Currow = 1
If allowpageing <> Empty Then



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.