Solved

ASP Dynamic table

Posted on 2008-10-14
10
201 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
  • 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

15 Experts available now in Live!

Get 1:1 Help Now