DataGrid function (reproduced) in ASP.NET in ASP

zhaozj2021-02-16  106

Original blog address: http://www.cnblogs.com/smartpig/

Since the use of the .NET's DataGrid, I also lazy to use the ASP drawing, so I want to have a history, and the function of accessing the DataGrid write a TBGRID class, which can be easily reused. It is more convenient to repeat labor each time. I hope to bring some convenience to the people you get. The usage is very simple, and the example behind it is clear. If you have any imperfect places, I hope everyone will discuss with me.

<

%

'

'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''

'

Programming by smartpig '

'

'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''

Class TBGRID

public

DataSource

'

data source

public

Style

'

Table style

public

HEADStyle

'

Head style

public

HeadItemStyle

'

Headwork

public

ItemStyle

'

Unit independent network

public

Columns

'

Columns need to be displayed

public

Alternate

'

Whether it is alternate

public

AlternateStyle

'

Even line style

public

Normalstyle

'

Normal style

public

DEFAULTSTYLE

'

Default cluster

public

PageSize

'

Page size

public

CURPAGE

'

current page

public

AllowPageing

'

Whether paging

public

Pageingstyle

'

Page number

Private

Templates

'

Custom unit item

'

Relationship between content

'

Column.add "Field", "HeadText"

'

AddTemplate ("HeadText", Template)

'

ItemStyle.Add "Field", "Style: ADSASD"

'

Datasource (Column.Keys (i))

Private

Sub

Class_initialize

'

Set the 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

'

Set the 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

Column.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 = # eeeee height = 20 "

Normalstyle

=

"

HEIGHT = 20 "

Case

Else

End

SELECT

End Sub

public

Sub

AddTemplate (Byval Columnname, Byval Template) Column.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

=

"

"

&

Style

&

"

>

"

&

VBCRLF

'

Draw Table HEAD

Response.write (TableStr) Response.write

"

"

)

for

Each

CLM in column.keys () TBStyle

=

HEADStyle

&

"

"

&

HeadItemStyle (CLM) TDStart

=

"

"

&

TBStyle

&

"

> "

TDEND

=

"

"

Response.write (TDStart) Response.write (Column (CLM)) Response.write (TDEND)

NEXT

Response.write

"

"

&

VBCRLF)

'

Draw Table Items

CURROW

=

1

IF

AllowPageing

<>

EMPTY

THEN

DataSource.pageSize

=

PageSize

Else

DataSource.pageSize

=

DataSource.Recordcount

end

IF

IF

CURPAGE

=

EMPTY

THEN

CURPAGE

=

1

end

IF

IF

CURPAGE

<

1

THEN

DataSource.absolute.absolute.com

=

1

end

IF

IF

CURPAGE

> =

DataSource.pagecount

THEN

DataSource.absolute.absolute.com

=

DataSource.pagecount

end

IF

IF

CURPAGE

> =

1

and

CURPAGE

<=

DataSource.pagecount

THEN

DataSource.absolute.absolute.com

=

CURPAGE

end

IF

for

CURROW

=

1

TO

DataSource.pageSize

IF

DataSource.eof

THEN

Exit

For

end

IF

Response.write

"

"

)

for

Each

CLM in column.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

=

"

"

&

TBStyle

&

"

> "

TDEND

=

"

"

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 (tdnd)

NEXT

Response.write

"

"

&

VBCRLF) DataSource.Movenext

NEXT

'

Draw Pageing Row

IF

DataSource.pagecount

>

1

and

Lcase

(PageingStyle)

<>

"

None

"

THEN

DIM

I Response.write

"

"

) Response.write

"

"

&

Columns.count

&

"

"

&

Pageingstyle

&

"

>

"

)

for

i

=

1

TO

DataSource.pagecount

IF

i

<>

CURPAGE

THEN

Response.write

"

Draw Table End

Response.write

"

"

)

End Sub

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.ItemStyle.Add "Password", "Align = Right"

'

TBGRID1.ItemStyle.Add "Modified", "Width = 100"

'

TBGRID1.AddTemplate "Modified", " {realname}

'

TBGRID1.COLUMNS.ADD "Password", "password"

'

TBGRID1.PAGESIZE = 5

'

TBGRID1.AllowPageing = true

'

TBGRID1.PAGEINGSTYLE = "Align = Right"

'

TBGRID1.CURPAGE = CINT (Request ("Page"))

'

TBGRID1.SHOW ()

'

Closedb

%

>

转载请注明原文地址:https://www.9cbs.com/read-15102.html

New Post(0)