Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Fancy Formatting of recordset output

Posted on 2003-11-26
4
Medium Priority
?
343 Views
Last Modified: 2009-07-29
OK, I'm building my own Schema Browser for my database - and it's all working fine, but I'm looking for a way of doing some slightly fancier formatting of my recordset output (pages currently in ASP with VBScript) ...

On Page1, I get the user to select a tablename from a list of table names from the database - this tablename is then passed into Page2 (the page that I want to reformat). Given a specific table name, I show the user a list of column names for that table - with a checkbox alongside each column name so to allow the user to indicate which columns they want to include in a subsequent SQL SELECT statement. Please note that this all works OK, my question is related to how I present the list of column names to the user .....

The relevant code snippet is as follows :
<CODE SNIPPET BEGINS ...>
  TableName = Request.QueryString("TableName")
  Set cn = Server.CreateObject("ADODB.Connection")
  cn.Open "DSN"
  Set TableInfo = Server.CreateObject("ADODB.Recordset")

  ' Just access the required tablename to pull out all of the column names
  TableInfo.Open TableName, cn, adOpenForwardOnly, _
               adLockReadOnly, adCmdTable

  ' TableInfo will now contain all of the column names from the TableName
  ' Create an HTML checkbox for each field in the RecordSet (ie column name
  ' in the table) for the table name passed in.
  ' Note that TableInfo.Fields.count will give you the number of columns ..
  ' Each column name (objField.Name) can be up to 24 characters long
  For Each objField in TableInfo.Fields

       Response.Write "<INPUT TYPE=CHECKBOX NAME=" & _
                                 vbQuot & "Field" & vbQuot & _
                                 " VALUE=" & _
                                 vbQuot & objField.Name & vbQuot & _
                                 " ID=" & _
                                 vbQuot & objField.Name & ">" & _
                                 "<LABEL FOR=" & _
                                 vbQuot & objField.Name & vbQuot & _
               ">" & objField.Name & "</LABEL>" & "<BR>"
  Next
<CODE SNIPPET ENDS ...>

  Produces a list like
  [check] firstcol
  [check] secondcol
  [check] thirdcol .... and so on vertically down the screen

  I'd ideally like to have these column names nicely formatted horizontally
  across the screen as in :

  [check] firstcol       [check] secondcol     [check] thirdcol      
  [check] fourthcol    [check] fifthcol          [check] sixthcol
 and so on .....

Ideally, I'd like to see the output formatted so that the checkboxes are nicely aligned under each other - it should be noted that each column name can be
a maximum of 24 characters.

Hopefully' I've explained this requirement clearly enough - so I'd love to see a workable solution .....
0
Comment
Question by:raymurphy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 21

Expert Comment

by:ap_sajith
ID: 9825725
Use this code..

' TableInfo will now contain all of the column names from the TableName
 ' Create an HTML checkbox for each field in the RecordSet (ie column name
 ' in the table) for the table name passed in.
 ' Note that TableInfo.Fields.count will give you the number of columns ..
 ' Each column name (objField.Name) can be up to 24 characters long
 Response.write "<Table width=100% cellpadding=2 cellspacing=2>"
 tdCount=0
 For Each objField in TableInfo.Fields
      If tdCount=3 Then
            response.write "</TR>"  & vbCRLF & "<TR ALIGN='LEFT'>" & vbCRLF
            tdCount=0
      End if
      Response.Write "<TD WIDTH='20px' ALIGN='LEFT'>&nbsp;</TD>" & vbCRLF
      Response.Write "<TD WIDTH='2px' ALIGN='LEFT'>"
    Response.Write "<INPUT TYPE=CHECKBOX NAME=" & _
                              vbQuot & "Field" & vbQuot & _
                              " VALUE=" & _
                              vbQuot & objField.Name & vbQuot & _
                              " ID=" & _
                              vbQuot & objField.Name & "></TD>" & _
                              "<TD CLASS='regular' ALIGN='LEFT'>&nbsp;<LABEL FOR=" & _
                              vbQuot & objField.Name & vbQuot & _
              ">" & objField.Name & "</LABEL></TD>"
      tdCount =  tdCount + 1
 Next
 Response.write "</Table>"

Cheers!!
0
 
LVL 21

Accepted Solution

by:
ap_sajith earned 1000 total points
ID: 9825748
small typo..


' TableInfo will now contain all of the column names from the TableName
' Create an HTML checkbox for each field in the RecordSet (ie column name
' in the table) for the table name passed in.
' Note that TableInfo.Fields.count will give you the number of columns ..
' Each column name (objField.Name) can be up to 24 characters long
Response.write "<Table width=100% cellpadding=2 cellspacing=2><TR ALIGN='LEFT'>"
tdCount=0
For Each objField in TableInfo.Fields
    If tdCount=3 Then
         response.write "</TR>"  & vbCRLF & "<TR ALIGN='LEFT'>" & vbCRLF
         tdCount=0
    End if
    Response.Write "<TD WIDTH='20px' ALIGN='LEFT'>&nbsp;</TD>" & vbCRLF
    Response.Write "<TD WIDTH='2px' ALIGN='LEFT'>"
   Response.Write "<INPUT TYPE=CHECKBOX NAME=" & _
                             vbQuot & "Field" & vbQuot & _
                             " VALUE=" & _
                             vbQuot & objField.Name & vbQuot & _
                             " ID=" & _
                             vbQuot & objField.Name & "></TD>" & _
                             "<TD CLASS='regular' ALIGN='LEFT'>&nbsp;<LABEL FOR=" & _
                             vbQuot & objField.Name & vbQuot & _
             ">" & objField.Name & "</LABEL></TD>"
     tdCount =  tdCount + 1
Next
Response.write "</TR></Table>"


Cheers!!
0
 

Author Comment

by:raymurphy
ID: 9827749
Excellent stuff, ap_sajith, your code gives me exactly what I was after - so thanks a lot for that !!!
0
 
LVL 21

Expert Comment

by:ap_sajith
ID: 9827799
Glad to help .. Thanks for the points..

Cheers!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question