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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variables Not Declared in Repeater

Status
Not open for further replies.

djs45uk

Technical User
Nov 7, 2004
103
GB
Hello

I'm using the following code to dynamically create a three column table of photographs retrieved from a database.

However, when compiling I am receiving an error to say that the variables count and myMod are not declared. Is this because I am using the variables inside the repeater?

Code:
<table>
<%
  Dim count, myMod As Integer
  count = 0
  myMod = 0
%>
<asp:Repeater ID="Photoviewer_Display" runat="server" DataSourceID="Photoviewer">
<ItemTemplate>
<%
  myMod = count Mod 3
    
  If (myMod = 0) Then Response.Write("<tr>")
    
  If Eval("photoviewerOrientation") = "L" Then
    Orientation = " border=0 width=72 height=48 border=0"
  Else
    Orientation = " border=0 width=48 height=72 border=0"
  End If
	
    'Write table data cell here
  Response.Write("<td><a href=photodisplay.asp?photoviewerID=" & Eval("photoviewerID") & " target=photodisplay><img src=" & Eval("photoviewerCategory") & "/thumbs/" & Eval("photoviewerURL") & Orientation & " ></a></td>")

  If (myMod = 2) Then Response.Write("</tr>")

  count = count + 1
%>
</ItemTemplate>
</asp:Repeater>

<%
  select case myMod
    case 0
      Response.Write("<td>&nbsp;</td><td>&nbsp;</td></tr>")
    case 1
      Response.Write("<td>&nbsp;</td></tr>")
    case 2
  end select
%>
</table>

PS You'll see that I'm using a couple if statements to evaluate data from my database. I am using...
Code:
If Eval("photoviewerOrientation") = "L" Then
to do this. Is that correct?

I'm grateful for any help!

Daniel
 
No, it's probably because of the classic ASP method of writing code that you are using. What you need to do (as there are many problems with the above code) is:

1) Switch to the code behind model (as suggested to you in thread855-1267403)

2) Use the Page Load event to bind any data to the Repeater

3) Use the RowDataBound event of the Repeater to apply any conditional formatting

4) Stop using the Response.Write

5) Remove the attributes from the table and use CSS

I'd suggest reading some basic tutorials on HTML/CSS and then some ASP.NET which also cover the basics as even with the relatively small example above, there are lots of mistakes that are making it much harder for you.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Great thanks!

I've been learning ASP .net for a few weeks but was just hoping to reuse an old piece of code which I had from when I was using classic ASP.

But I do get what you're saying! I need to do this bit from scratch.

Thanks for your help - I'll get the book out and give it ago.

Thanks again

Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top