Link to home
Start Free TrialLog in
Avatar of abbeygroup
abbeygroup

asked on

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

Hi

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.

Thanks
Avatar of wesbird
wesbird

See:

http://msdn.microsoft.com/library/default.asp?url=/workshop/author/tables/buildtables.asp

"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
   
    cnn.open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
           "Data Source=C:\Program Files\Microsoft Office\Office\Samples\northwind.mdb;" & _
           "User Id=admin;" & _
           "Password="

    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
        rs.MoveFirst
       
        strHTML = strHTML & "<tr>"
        For j = 0 To rs.Fields.Count - 1
            strRS = CStr(rs(j).Name)
            strHTML = strHTML & "<th>" & strRS & "</th>"
        Next
        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>"
                Else
                    strRS = CStr(rs(j))
                End If
                strHTML = strHTML & "<td>" & strRS & "</td>"
            Next
            strHTML = strHTML & "</tr>"
           
            rs.MoveNext
        Wend
    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?

Wes


ASKER CERTIFIED SOLUTION
Avatar of wesbird
wesbird

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial