How does one create a dynamic Table or Grid using DHTML (VB)

Posted on 2004-11-05
Last Modified: 2010-05-02

I have created a simple DHMTL Project within VB6. The DHTML Pages communicate with SQL Stored Procedures.

I know how to get the DHMTL Pages to communicate with my database, but I don’t know how to create a dynamic table or grid.

I would like the following:
- I want to create a function (within VB's DHTML) which creates a table or grid dynamically on my page.
- The table or grid will be generated from any stored procedure or record set I choose.
- I will require the capability of sorting on the columns (when clicking a column header)
- I also want to be able to read a value (from one of the columns) in the selected row (selected by user).

If anyone could provide some examples of how to do the following I would be extremely greatful. You could also recieve 500 points as a token of my appreciation.

Question by:abbeygroup
    LVL 7

    Expert Comment


    "innerText and innerHTML properties of the table and tr objects are read-only."

    Unfortunately it's not possible to replace the innerHTML of tables so you'll have to regenerate the table by adding and removing rows - or replacing the entire table.  The link above should help you and clarify this.
    LVL 7

    Expert Comment

    LVL 7

    Expert Comment

    You'll need something like this:

    Private Sub DHTMLPage_Load()
        Dim cnn As New ADODB.connection
        Dim cmd As New ADODB.Command
        Dim rs As ADODB.Recordset
        Dim strHTML As String
        Dim j As Integer
        Dim strRS As String
       "Provider=Microsoft.Jet.OLEDB.4.0;" & _
               "Data Source=C:\Program Files\Microsoft Office\Office\Samples\northwind.mdb;" & _
               "User Id=admin;" & _

        cmd.ActiveConnection = cnn
        cmd.CommandText = "SELECT * FROM Customers"
        Set rs = cmd.Execute
        strHTML = "<table id='test' class='sortable'>"
        If Not rs.EOF And Not rs.BOF Then
            strHTML = strHTML & "<tr>"
            For j = 0 To rs.Fields.Count - 1
                strRS = CStr(rs(j).Name)
                strHTML = strHTML & "<th>" & strRS & "</th>"
            strHTML = strHTML & "</tr>"
            While Not rs.EOF And Not rs.BOF
                strHTML = strHTML & "<tr>"
                For j = 0 To rs.Fields.Count - 1
                    If IsNull(rs(j)) Then
                        strRS = "<NULL>"
                        strRS = CStr(rs(j))
                    End If
                    strHTML = strHTML & "<td>" & strRS & "</td>"
                strHTML = strHTML & "</tr>"
        End If
        strHTML = strHTML & "</table>"
        DHTMLPage.Document.body.innerHTML = strHTML
    End Sub

    Still trying to figure out the sortable columns though.  You may have to transcript the Javascript to VB?


    LVL 7

    Accepted Solution

    One very important thing to note here is that with WinXP SP2 you get a popup blocker message every time you try to debug the code.  Serious investigation of network policies is requred if this is for a commercial app.  You'd be much better off using a Webclass on an ASP server, which also would sort out the Javascript integration problem too.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now