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


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.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


"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.
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?


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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.