Use ASP.NET to display relevant data related to the main role table in the same web page

xiaoxiao2021-03-06  61

table of Contents

method

Naming Rules for the ID of Tables and ImageButtons

Estimation of the length of Table on the web page

Main procedure

Event process

Applications

Method:

For each table in the DataSet, if there is a sub-table, the field name of this table and each record line are displayed on the web page on the webpage, and the first column of the record line Table ImageButton so that the program controls the Table or Tables formed by the record line of expanding or closing the corresponding sub-table. For each record line, the sub-table has the corresponding record line, and the sub-table has a sub-table, then the sub-table repeats the above process, the field name of the sub-table is displayed on the web page on the web page. Table, and put an ImageButton in the second column of the record line Table, and vibrant the field name of the sub-table with the corresponding record line on the web page as a table. With the Table's Visible property, you can control the display of the loop accordingly on the subthech. It is clear that this process can be implemented using recursion calls.

Naming Rules for the ID of Tables and ImageButtons:

Use the corresponding tables of ImageButton, program control webpage, and naming of these imageButton.id and Table.ID require a certain rule.

For the first home table in DataSet:

Web page table generated by the field line name T0

The IDs of the web tables TABLES generated by the recording line are T1, T2, ... TN respectively, IMAGeButton.ID corresponding to these tables, E2, ... EN, here N: The number of record lines of the primary table

Subsheet in DataSet:

The record lines in the sub-table are part of a record line belonging to the primary table, so these recorded web tables are also part of the Table for generating web pages for a record line of the primary table, such as Tables named T2. T2-0, T2-1, T2-3 ..., where T2-0 is a table ID generated on the field name of the child table, and the rest is pushed, and if the sub-table has no sub-table, that is, finally A sub-table, T2-0 is a Table.ID name that contains a field name row of a sub-table and a corresponding sub-table record line generated on the web page.

ImageButton.ID corresponding to these table.id is named E2-1, E2-2, ....

Estimation of the field length of Table on the webpage:

Each table in the DataSet generates some Table on the web page, which should be the same. That is the same length of Tables, the same length. Function subroutine setcellsize calculates the number of average characters of the DataTable, and the number of characters of the field name, and takes the big, if a record or field name of the field is an ASCII character, its character number is harder. Use this data to estimate the display length of the corresponding field of the Table on the web page.

The following is the program of SetCellsize, which is easy to understand.

Function setcellsize (MyTable as dataatable)

Dim Myrow As DataRow

DIM I, J, K, M AS Integer

DIM AA () AS Integer

DIM MyBool As Boolean

m = mytable.columns.count-1

Redim aa (m)

For i = 0 TO M

AA (i) = 0

NEXT

For Each MyRow In MyTable.Rows' calculates the average character length of each field

For i = 0 to myTable.columns.count-1

DIM mystr as string

MyStr = MyRow (MyTable.Columns (i)). Tostring

J = LEN (MySTR)

IF J> 0 THEN

MyBool = true

For K = 1 to j 'to determine whether each item in the DataTable includes Chinese characters

DIM str1 as char = MID (MySTR, K, 1)

IF ASCW (str1)> 255 Then 'has non-ASCII characters

MyBool = false

EXIT for

END IF

NEXT

If MyBool Then J = (J / 2 0.5) 'is all ASCII characters, the string length is half

AA (i) = j

END IF

NEXT

Next Myrow

K = myTable.Rows.count

For i = 0 TO M

AA (I) = AA (i) / k 'data of each column of each column of each column of DataTable

NEXT

For i = 0 to myTable.columns.count-1 'for each field name

DIM str2 as string = myTable.columns (i) .Columnname

J = LEN (STR2)

IF J> 0 THEN

MyBool = true

Fork = 1 to j 'Decision field name includes Chinese characters

DIM str1 as char = MID (STR2, K, 1)

IF ASCW (str1)> 255 Then 'has non-ASCII characters

MyBool = false

EXIT for

END IF

NEXT

If MyBool Then J = (J / 2 0.5) 'ASCII characters, the string length is halved

IF j> AA (i) TEN AA (i) = j

END IF

NEXT

SetCellsize = aa

END FUNCTION

Main procedures:

Subprogram showTables set some initial values ​​and then call the subroutine showchildrows.

Parameter Description of Subprogram ShowChildrows:

Rows: It is a DataRow array that calls ShowChildRows for the first time, it is a DataTable all record line. When recursive in the future, it is a record line with a subtray related to the parent table a record line.

MyTable: The DataTable belongs to the Rows, the program will use its columns, namely the field name row.

AA: The one-dimensional integer array returned by the function subroutine setcellsize.

Spaces: Integer parameters, which are used to display Tables on the web, and several null cells should be set to display the membership of Table.

Signal: String parameters, ImageButton ID value, used to generate associated Tables and ImageButtons IDs.

Because adding a TABLE control to the web page, there should be an ID of the Form1 on the web page.

Dynamically create a table, first, create a TableCell object, that is, the unit's cell, add the content of the unit: Set the text property, or add a control to the Tablecell's Control.Controls collection, Some units add imageButton controls; then create a TableRow to indicate the rows in the table, add the previous TableCell object to the Cells collection of the tablelow. Finally, add tablelow to the ROWS collection of the Table control. The following is the program:

Sub ShowTables (MySet As DataSet)

DIM SPACES AS INTEGER = 0

DIM AA () AS Integer

DIM I, D AS INTEGER

DIM signal as string = "" "

DIM myTable as dataatable = mySet.tables (0)

DIM ROWS () AS DATAROW

D = myTable.Rows.count-1

Redim Rows (D)

For i = 0 to myTable.Rows.count-1

Rows (i) = myTable.Rows (i)

NEXT

AA = setcellsize (MyTable)

Call showchildrows (Rows, AA, MyTable, Spaces, Signal)

End Sub

Sub showchildrow (Rows () AS DataRow, AA () AS Integer, MyTable As DataTable, Spaces As Integer, Signal As String

DIM I, J, K, M, Leng AS Integer

DIM FONTSIZE AS INTEGER = 10

Dim Myrow As DataRow

DIM Mycol as datacolumn

DIM TESTTABLE As Table

Dim Cell As Tablecell

Dim row as tableerow

DIM MyBool As Boolean

DIM MyImage as imagebutton

Dim Childrows () AS DATAROW

Dim ChildTable As DataTable

Dim Myrel AS DataRelation

DIM BB () AS Integer

DIM CellStyle As New TableItemStyle

CellStyle.BorderWidth = Unit.pixel (1)

CellStyle.Borderstyle = BorderStyle.solid

CellStyle.wrap = FALSE

If MyTable.Childrelations.count = 1 Then '

Myrel = myTable.Childrelations (0)

ChildTable = Myrel.childTable

m = childtable.columns.count-1

Redim BB (M)

MyBool = true

BB = setcellsize (childtable)

END IF

TestTable = New TABLE

TestTable.BorderWidth = Unit.pixel (1)

TestTable.cellspacing = 0

TestTable.cellpadding = 0

TestTable.font.name = "Song"

TestTable.Font.size = fontunit.point (fontsize) TestTable.visible = true

If Signal <> "" THEN 'recursive call, the value of Table.ID formed by the field name row

Leng = len (signal)

TestTable.ID = "T" & MID (Signal, 2, Leng-1) & "-0"

TestTable.visible = false

Else

TestTable.id = "t" & "0" 'initially, the Table.ID formed by the field name line

TestTable.visible = TRUE

END IF

Form1.Controls.add (TestTable)

'********************************************************************************************* *

Row = new tableerow

Row.BorderWidth = Unit.pixel (1)

m = rows.length

IF Spaces> 0 THEN

For i = 1 to Spaces

Cell = New TableCell

Cell.ApplyStyle (CellStyle)

Cell.width = unit.pixel (13)

If not myBool Then Cell.rowSpan = m 1

Row.cells.Add (Cell)

NEXT

END IF

IF myBool.

Cell = New TableCell

Cell.ApplyStyle (CellStyle)

Cell.backcolor = color.lightgray

Cell.Bordercolor = color.black

Cell.width = unit.pixel (13)

Row.cells.Add (Cell)

END IF

m = mytable.columns.count-1

For i = 0 TO M

Cell = New TableCell

DIM STR2 AS STRING

Cell.ApplyStyle (CellStyle)

Cell.backcolor = color.lightgray

Cell.Bordercolor = color.black

Cell.Text = MyTable.Columns (i) .COLumnName

Cell.horizontalalign = horizontalalign.center

K = (FontSize 6) * aa (i)

Cell.width = Unit.pixel (k)

Row.cells.Add (Cell)

NEXT

TestTable.Rows.Add (Row)

'************* The following procedure is a record of the table's record table, TABLES *******************************

For i = 0 to rows.Length-1

IF myBool.

TestTable = New TABLE

TestTable.BorderWidth = Unit.pixel (1)

TestTable.cellspacing = 0

TestTable.cellpadding = 0

TestTable.font.name = "Song"

TestTable.font.size = fontunit.point (fontsize)

TestTable.visible = TRUE

IF signal <> "" ThentestTable.id = "T" & MID (Signal, 2, Leng-1) & "-" & (i 1) .tostring

TestTable.visible = false

Else

TestTable.ID = "t" & (i 1) .tostring

TestTable.visible = TRUE

END IF

Form1.Controls.add (TestTable)

END IF

Myrow = ROWS (i)

Row = new tableerow

IF myBool.

IF Spaces> 0 THEN

Fork = 1 to Spaces

Cell = New TableCell

Cell.ApplyStyle (CellStyle)

Cell.width = unit.pixel (13)

Row.cells.Add (Cell)

NEXT

END IF

Cell = New TableCell

Cell.width = unit.pixel (13)

Cell.ApplyStyle (CellStyle)

MyImage = new imageButton

MyImage.Imageurl = "close.gif"

IF signal <> "" "

MyImage.id = Signal & "-" & (i 1) .tostring

Else

MyImage.id = "e" & (i 1) .tostring

END IF

AddHandler MyImage.command, Addressof ImageButton_Command

MyImage.ImageAlign = imageAlign.absmiddle

Cell.controls.add (MyImage)

Row.cells.Add (Cell)

END IF

m = mytable.columns.count-1

For j = 0 TO M

Cell = New TableCell

Cell.ApplyStyle (CellStyle)

Cell.Text = MyRow (MyTable.columns (j)). Tostring

K = (FontSize 6) * aa (j)

Cell.width = Unit.pixel (k)

Row.cells.Add (Cell)

NEXT

TestTable.Rows.Add (Row)

If MyBool Then 'is from the table, recursive call

DIM SPACES2 AS INTEGER

Spaces2 = SPACES 1

Childrows = Myrow.getChildrows (Myrel)

Call showchildrows (Childrows, BB, ChildTable, Spaces2, MyImage.ID)

END IF

NEXT

End Sub

Event process:

A naming rule is given in the section of Tables and ImageButtons, which is given here:

If you click ImageButton with an ID of E1, the Table of the TABLE on the corresponding web page is T1, and the corresponding record line on the T1-related subtrack is formed on the web page to T1-1, T1-2, .. .t1-n of Tables, where n is the corresponding number of rows on the child table, while the T1-0 is the table of the field name of the sub-table to form a Table on the web page. If the imageURL of E1 is "" Close.gif, it is set to "" Open.gif, and the Visible property of T1-0, T1-1, ... T1-N is set to TRUE. Conversely, in addition to change E1's imageURL to Close.gif and will change T1-0, T1-1, ... T1-N's Visible property, if T1-1, T1-2, ... T1 -n has an ImageButton for E1-1, E1-2, ... E1-N, and some imageURLs in these imageButtons are Open.gif, and some record lines of subtables of iMumes. Tables is open, then these imageurls are set to Close.gif. Article Title: Using Web Services Enhancements To Send SOAP Messages with Attachments

The procedure is as follows:

Sub ImageButton_Command (Sender As Object, E As CommandEventArgs)

DIM MyControl As Control

DIM STR1 AS STRING

Dim Leng As Integer

Str1 = sender.id

Leng = LEN (STR1)

Str1 = "T" & MID (str1, 2, leng-1) & "-"

If sender.imageurl = "close.gif" then

Sender.imageurl = "open.gif"

For Each MyControl in form1.controls

DIM POS1 AS INTEGER = INSTR (Leng 2, MyControl.ID, "-")

If Left (MyControl.ID, Length 1) = str1 and pos1 = 0 Then MyControl.visible = true

NEXT

Else

Sender.imageurl = "close.gif"

For Each MyControl in form1.controls

Dim str0 as string = myControl.ID

If Left (MyControl.ID, Length 1) = str1 then

DIM DTABLE As Table

DTABLE = CTYPE (MyControl, Table)

If DTABLE.CONTROLS.COUNT> 0 THEN

Dim RowControl As Control

For Each RowControl in DTable.Controls

DIM DROW AS TABLEROW

Drow = ctype (RowControl, TableRow)

If Drow.Controls.count> 0 THEN

DIM CellControl as Control

For Each CellControl in Drow.Controls

DIM DCELL AS TABLECELL

DCell = CType (CellControl, Tablecell)

IF dcell.controls.count> 0 THEN

DIM ImageControl as Control

For Each ImageControl in Dcell.Controlsdim Dimage As ImageButton

Dimage = ctype (ImageControl, ImageButton)

DIMAGE.ImageURL = "close.gif"

NEXT

END IF

NEXT

END IF

NEXT

END IF

MyControl.visible = false

END IF

NEXT

END IF

End Sub

Applications:

Taking the Rosewin database as an example, the database has three table files, orders and orders, two tables, customers and orders, have a pair of relationships, orders and orders in the field name "Order ID" "There is a couple of relationships. The following procedure connects the database to form a DataSet, call the subroutine showtables.

<% @ Import namespace = system.data.oledb%>

<% @ Import namespace = system.data%>

<% @ Import namespace = system.drawing%>