Link to home
Start Free TrialLog in
Avatar of timpoynter
timpoynter

asked on

ASP Dynamic table

Hi
I have developed an app using Dreamweaver and sql server, its using ASP Javascript. I am not too hot on ASP I am a dba, hence I have used dreamweaver wizards, etc  to code the pages.

I have a store procedure that creates a dynamic table where the number of rows and number of columns can change. The scenario is that I am reporting on an application that stores documents in sub folders and the documents can have different statuses, so I am reporting on the number of documents at each status in each subfolder and the number of subfolders and status can change depending on the config of the app, hence the dynamic table.

I need to create a dynamic table in Dreamweaver to display this dynamic table and would like to have control over the visual aspects of the table (border, widths, etc), can anyone help?

I understand that this will need to be coded and isn't part of the dreamweaver tools but please bear in mind I am not a coder
Avatar of CCongdon
CCongdon
Flag of United States of America image

Here's an idea...it's kind of cheating, but it might work.
Figure out what the max columns are for your biggest table. Create the table in dreamweaver to be this big. Now, in your stored procedure, any table returned that isn't the same number of columns as your biggest table, add columns to them and just return null or an empty string.
The trick is that if null/empty string is shown inside of a <td>...the <td> isn't actually 'built' on screen.
The rows are easier, and DW actually has a built in behavior for that. Highlight the row that has data output and select Server Behaviors/Repeat Region.
Avatar of timpoynter
timpoynter

ASKER

Hi
Thanks for the comment, this had crossed my mind, although I would like a cleaner solution.

I will wait and see if there are any helpful asp coders out there who can put it in simple enough terms :)

If not I'll send the points your way, I appreciate the comment
Remember though, when you create the table, you really only need a couple of rows.
The first row(s) will show your headers including column names (if you need them).
The next row should be your data display row and most likely will only be a single row with the repeat region behavior applied.
Then you can have some footer row(s) after if you need.
Another thing is that you'll probably want to alias your column names in your stored procedure. That way you can miniminze the web site coding. You could do something as simple as SELECT FirstName col1, LastName col2, Address col3.... and just reference col1, col2, col3 in DW. Especially important if your different outputs have different column names. You could re-do the code and reference the column numbers directly from the recordset object, but I figure steering you to doing more through the DB side might be more effective at this point.
Well, if you give me a few, I can probably come up with something from the coding side. I'm just a little creaky in server side JavaScript... I do most of my programming in VBScript.
OK, I had to look up a couple of things... like I said, I don't do a lot of server side JScript, so not having a for each was kind of a pain (It is in JavaScript, but apparently not JScript). However, I came up with something using the Enumerator object and it seems to work quite nicely.
There might be a more efficient way of doing this, but it does work. I tried recycling the existing Enumerator object by just using a moveFirst on it, but that caused it not to enter the for loops to disply data. I was getting <tr></tr> but nothing in between.... that's why I just reset 'e' in each loop.
Modifying each indivdual cell for formatting is kind of tough. I've got an idea and I will post it again in a moment.
I have tried this code on three different tables on my end, and it does work with them.
You will need to replace references to 'Recordset1' with the name of your recordset object. And of course, your recordset needs to be opened before getting to this code.

<table width="100%" border="1" cellspacing="0" cellpadding="0">
  <tr>
  <%
     function showNull (str) {
	   if (str==null || str=="") {return "&nbsp;";}
	   else {return str;}
	 }
     var x;
     var e = new Enumerator(Recordset1.Fields);
  	 for(; !e.atEnd(); e.moveNext()) {
		x = e.item();%>
    <td><%=x.Name.replace(null,"&nbsp;")%></td>
    <%  } %>
  </tr>
  <% for(;!Recordset1.EOF; Recordset1.MoveNext) {
  		var e = new Enumerator(Recordset1.Fields); %>
  <tr>
    <% for(; !e.atEnd(); e.moveNext()) {
       x = e.item();%>
       <td><%=showNull(x.Value)%></td>
    <%  } %>
  </tr>
  <% } %>
</table>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of CCongdon
CCongdon
Flag of United States of America image

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
Excellent thank you very much for your posts, I have been busy since you posted and its a little late to get my head round it now but will try it out in the morning and let you know, thanks again

Damn your good.
Sorry it took so long to try it out.
Worked first time and managed to get the css right for the left column and header.

I can't thank you enough.

Here have your well deserved points
Thanks again
Glad it worked out. Would've been a little easier for me in VBScript :P I had actually never done an enumerator in JavaScript, so that was new to me...but I had a solid idea of the exact flow of programming you needed, so once I knew what object did what I needed...well you see the result :)