Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Thumbnail gallery

Status
Not open for further replies.

jdmaynard

Programmer
Mar 12, 2001
11
CA
In ASP I used to make a thumbnail display something like this:
------------------------------------
Code:
<% dim counter = 0 %>
<head>
</head>
<body>
<table>
 <tr>
 <% While (NOT rsItems.EOF)%>
    <td class=&quot;gallery&quot;>
      <a href=&quot;image.aspx?ID=<%=(rsItems.Fields.Item(&quot;ID&quot;).Value)%>&quot;>
      <img src=&quot;<%=(rsItems.Fields.Item(&quot;Path&quot;).Value)%>&quot;>
      </a>
    </td>
  <% 
  counter=counter+1
  rsItems.MoveNext()
  If (counter Mod 4 = 0) then 
    %>
    <td></td>
    </tr>
  <%end if%>
<%Wend
%>
</table>
...etc.
-------------------------------
Basically I made a table on the fly with (in this case ) 4 columns and as many rows as the recordset required.

I've spent two nasty days trying to figure out how to do something like this in ASP.NET. I'm sure there's some real easy way, but I'm beat (so far).

My counter, for example, loses scope between when I create it and when I use it.
I'm sure I should be using some cunning code-behind trick but it entirely escapes me.

Any help greatly appreciated.

Thanks

DOug
 
You could use a DataList control bound to a database call and then have the thumbnail images scroll horizontally across the screen. :)
 
I've found lots of ways to place the thumbnails horizontally across the screen. Mostly my problem involves using the counter to start new rows.
 
Yeah, that's why you could use a DataList control or a Repeater and have a new table row for each image.
 
Sorry, Jason:
Let me try to explain it again.

I'm trying to display the thumbnails in a table format with four pictures per row, and who knows how many rows.

My problem is telling when I've displayed every fourth image so I can go to a new row. My counter variable seems to disappear every time the script block happens. It would be nice if the repeater had a counter I could look at, but I haven't seen one yet.

DOug
 
OK...I see now. You could probably get away with building a DataTable programatically using the same logic as you did in your original code snippet, using inline server-side code <% ... %> and using the same logic. You just have to declare the counter variable in the right pace so it doesn't lose scope, like you said.

You'd could also create 4 new DataColumns to hold a series of thumbnails (say, by using from i=0 to 4) and then when i=5, use the DataTable's NewRow() method and repeat. This would be the easiest way.

Alternatively, I did something very similar to this (reading graphics and textual data from an XML file and then building a thumbnail page). In my way, I programmatically built a series of HtmlTableRows based on an index (the total number of pix to use). Then, I wrote a very short custom class to hold the index, name, URL, etc. and then imported this data into the HtmlTable object.

I can send you the code for the latter, if you want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top