Solved

ASP Dynamic table

Posted on 2008-10-14
10
206 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:timpoynter
[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
  • 6
  • 4
10 Comments
 
LVL 9

Expert Comment

by:CCongdon
ID: 22711195
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.
0
 

Author Comment

by:timpoynter
ID: 22711227
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
0
 
LVL 9

Expert Comment

by:CCongdon
ID: 22711245
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.
0
Independent Software Vendors: 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!

 
LVL 9

Expert Comment

by:CCongdon
ID: 22711264
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.
0
 
LVL 9

Expert Comment

by:CCongdon
ID: 22711633
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

0
 
LVL 9

Accepted Solution

by:
CCongdon earned 500 total points
ID: 22711738
OK, here's take two with formatting ability.
The formatting is dependent upon CSS. There are two 'references'
header<COLUMN_NAME>
col<COLUMN_NAME>
The header one is an ID, so you can't use it anywhere else on the page. Use that to define the header field for each column
The col one is simply a class. It applies to every row in that column INCLUDING the header.
Basically, do all of your formatting in the col one and specific formatting in the header one. Anything in the ID should override the class.
The nice thing about this is that if you know what columns you will have in different situations, the table can auto-format the columns based on the CSS you already have in play.
Also, if you specify CSS for the table itself, you can have generic formatting in case you didn't specify that column in your CSS.

<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 id="header<%=x.Name%>" class="col<%=x.Name%>"><%=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 class="col<%=x.Name%>"><%=showNull(x.Value)%></td>
    <%  } %>
  </tr>
  <% } %>
</table>

Open in new window

0
 

Author Comment

by:timpoynter
ID: 22715622
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

0
 

Author Comment

by:timpoynter
ID: 22733278
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
0
 

Author Closing Comment

by:timpoynter
ID: 31505860
Thanks again
0
 
LVL 9

Expert Comment

by:CCongdon
ID: 22734686
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 :)
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

705 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