Abstract: DataSet is a representation of a dataset in memory. A dataset can have a master-slave relationship with a data table. In access, this relationship is intuitive, this article discusses the program design and program for intuitively displaying corresponding data with a master-slave relationship on the same web page. Directory method tables and imagebuttons ID naming rules estimation of the length of the table field on the webpage main program event process application instance Method: for each table in dataset, if there is a sub-table, the field name row and each record row of this table are displayed as tables with only one row on the webpage, set imagebutton on the first column of the record row table so that the program can control the table or tables formed by the record row of the corresponding sub-table. For each record row, the sub-table has a corresponding record row. If the sub-table has a sub-table, the sub-Table repeats the above process, the field name row and corresponding record row of the sub-table are displayed as a table with only one row on the webpage, and an imagebutton is placed on the second column of the table record row, on the contrary, the field name row of the sub-table and the corresponding record row are displayed as a table on the webpage. You can use the visible attribute of table to control the display of corresponding record rows in the sub-table. Obviously, recursive calls can be used to implement this process. Naming rules for tables and imagebuttons IDs: Click imagebutton to control the display and hiding of corresponding tables on the webpage. ID and table. the naming of IDS requires certain rules. For the first master table in Dataset: the ID of the webpage table generated by the field row is T0. the IDs of the webpage tables generated by the record row are T1, T2 ,... TN, The imagebutton corresponding to the tables. the ID is named E1, E2 ,... n: The number of record rows in the master table. For the sub-table in dataset, the record rows in the sub-Table belong to a record row in the master table, therefore, the Web tables generated by these record rows also belongs to the table of a page generated by a record row in the master table, such as tables of T2 named t2-0, t2-1, t2-3 ..., the t2-0 is the table generated on the web page for the field name row of the child table. ID, and so on. If the sub-table has no sub-table, that is, the last sub-table, the t2-0 is the table generated on the web page by the field name row containing the child table and the corresponding child table record row. id. Imagebutton. ID corresponding to these table. IDs are named e2-1, e2-2,... respectively ,.... Estimation of the Field Length of the table on the webpage: Each table in the dataset will generate some tables on the webpage. The external forms of these tables should be the same. That is, the same cell length of tables should be the same. The setcellsize function is used to calculate the average number of characters in each field of the able and the number of characters in the field name. If a field's record or field name is an ASCII character, the number of characters is halved. With this data, you can estimate the display length of the corresponding table fields on the webpage. The following is the setcellsize program, which is easy to understand.
Function setcellsize (mytable as datatable) dim myrow as datarowdim I, J, K, M as integerdim AA () as integerdim mybool as booleanm = mytable. columns. count-1redim AA (m) for I = 0 to m aa (I) = 0 nextfor each myrow in mytable. rows calculate the average 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 'determine whether each item in the able contains the Chinese character 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) 'Both are ASCII characters, and the string length is halved AA (I) + = J end if nextnext myrowk = mytable. rows. countfor I = 0 to m aa (I) = AA (I)/K' average length of each column of the able nextfor 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 for k = 1 to J' determine whether the field name contains 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, string Length halved if j> AA (I) Then AA (I) = J end ifnextsetcellsize = aaend Function
Main Program: The subroutine showtables sets some initial values, and then calls the subroutine showchildrows. Parameter description of the subroutine showchildrows: rows: Is a datarow array. When showchildrows is called for the first time, it is all the record rows of the datatable. When showchildrows is called recursively later, it is some record rows of the child table related to a row in the parent table. Mytable: The able to which the rows belongs. The program uses its columns, that is, the field name row. AA: one-dimensional integer array returned by the function subroutine setcellsize. Spaces: integer parameter. It is used to display tables on a webpage. Several empty cells should be set on the left of these tables to display the table affiliation. Signal: string parameter, id value of imagebutton, used to generate related tables and imagebuttons IDs. To add a table control to a webpage, a form control with the ID of form1 should be added to the webpage. There are three steps to create a table dynamically. First, create a tablecell object, that is, a cell in the row. There are two ways to add the content of a cell: Set the text attribute or control the content to tablecell. add controls to the controls set, and add the imagebutton control to some cells in the program. Next, create tablerow to represent the rows in the table and add the previously created tablecell object to the cells set of tablerow. Finally, add tablerow to the table control's rows collection. The following is a program:
Sub ShowTables(mySet as DataSet)dim spaces as integer=0dim aa() as integerdim i,d as integerdim signal as string=""dim myTable as dataTable=mySet.tables(0)dim rows() as DataRowd=myTable.rows.count-1redim rows(d)for i=0 to myTable.rows.count-1 rows(i)=myTable.rows(i)nextaa=SetCellSize(myTable)Call ShowChildRows(rows,aa,myTable,spaces,signal)End Sub
Sub showchildrows (rows () as datarow, AA () as integer, mytable as datatable, spaces as integer, signal as string) dim I, J, K, M, leng as integerdim fontsize as integer = 10dim myrow as datarowdim mycol as datacolumndim testtable as tabledim cell as tablecelldim row as tablerowdim mybool as booleandim myimage as your childrows () as datarowdim childtable as datatabledim myrel as datarelationdim BB () as integerdim cellstyle as new tableitemstylecellstyle. borderwidth = unit. pixel (1) cellstyle. borderstyle = borderstyle. solidcellstyle. wrap = falseif mytable. childrelations. count = 1 then' there is a slave table myrel = mytable. childrelations (0) childtable = myrel. childtable M = childtable. columns. count-1 redim BB (m) mybool = true BB = setcellsize (childtable) end iftesttable = new tabletesttable. borderwidth = unit. pixel (1) testtable. cellspacing = 0testtable. cellpadding = 0testtable. font. name = "" testtable. font. size = fontunit. point (fontsize) testtable. visible = trueif signal <> "" then': The table formed by the field name row in recursive calling. ID value Leng = Len (signal) testtable. id = "T" & Mid (signal, 2, leng-1) & "-0" testtable. visible = falseelse testtable. id = "T" & "0. id testtable. visible = trueend ifform1.controls. add (testtable) ******************* * ROW = new tablerowrow. borderwidth = unit. pixel (1) M = rows. lengthif 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) nextend ifif mybool then cell = new tablecell cell. applystyle (cellstyle) cell. backcolor = color. lightgray cell. bordercolor = color. black cell. width = unit. pixel (13) Row. cells. add (cell) end IFM = mytable. columns. count-1for 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) nexttesttable. rows. add (ROW) ***************** * *** for I = 0 to rows. length-1 If mybool then testtable = new table testtable. borderwidth = unit. pixel (1) testtable. cellspacing = 0 testtable. cellpadding = 0 testtable. font. name = "" testtable. font. size = fontunit. point (fontsize) testtable. visible = true IF signal <> "" Then testtable. 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 tablerow if mybool then if spaces> 0 then for k = 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 <> "" Then 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' if there is a slave table, recursively call dim spaces2 as integer spaces2 = spaces + 1 childrows = myrow. getchildrows (myrel) Call showchildrows (childrows, BB, childtable, spaces2, myimage. ID) end ifnextend sub
Event process: the naming rules are provided in the "tables and imagebuttons ID naming rules" section. For example: If you click imagebutton with ID E1, it corresponds to the page on the table ID T1, T1-related child table corresponding record lines on the page form ID for t1-1, t1-2 ,... the tables of the t1-n, where N is the corresponding number of records on the child table, And the t1-0 is the table formed on the web page by the field name row of the child table. If the imageurlof e1is always close.gif, set it to always writable open.gif, and set the visible attribute of the t1-0, t1-1,... t1-n to true. . Article Title: using Web Services enhancements to send soap messages with attachments:
Sub ImageButton_Command(Sender as object,e as CommandEventArgs)dim myControl as Controldim str1 as stringdim leng as integerstr1=sender.idleng=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,leng+1)=str1 and pos1=0 then myControl.visible=true nextelse Sender.ImageUrl="close.gif" for each myControl in form1.controls dim str0 as string=myControl.id if left(myControl.id,leng+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.controls dim 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 nextend ifEnd Sub
Application Example: Taking the arms database as an example, the database has three table files: customer, order, and order details, the customer and order tables have one-to-many relationships with the field name "Customer ID". The order and order details have one-to-many relationships with the field name "Order ID. The following program connects to the database to form a dataset, and then calls the subroutine showtables.
<% @ Import namespace = system. data. oledb %> <% @ import namespace = system. data %> <% @ import namespace = system. drawing %> <HTML> Copy the above program to notepad and copy the previous program to the corresponding subroutine addition. Note: the text disconnection error may occur during the above process, after modification, name it. aspx file. The running result is as follows:
Author: Cao guoxuan