SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Need Asp Help!!

  1. #1
    SitePoint Addict
    Join Date
    Apr 2003
    Location
    canada
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Need Asp Help!!

    I'm wondering for anyone out there who can help me.
    I have no idea how to code a table where each table row is a diffrent colour.
    EX. Row 1 is RED Row 2 is Blue. Row 3 is Red again. anyway we all get the idea any help on this would be greatly appreciated
    Thanks
    capples3

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    How about something like this?
    Code:
    <table>
    <%
    Dim setColor, color1, color2
    color1 = "#000000"
    color2 = "#ffffff"
    For x = 0 to 20
    If x mod 2 = 0 Then
    setColor = color1
    Else
    setColor = color2
    End If
    %>
    <tr style="background-color: <%=setColor%>;">
    <td>Your stuff here</td>
    </tr>
    <%
    Next
    %>
    </table>
    This will alternate background colors between black and white. Change color1 and color2 variables to the colors you need, and you should be set.

  3. #3
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's a simple but elegant sub that I wrote to do this in a resuable way, written because I need to toggle variables between two states so often...

    Code:
    <%
    Sub ToggleVariable(ByRef Variable, ByVal FirstValue, ByVal SecondValue)
    	If (Variable <> FirstValue) Then
    		Variable = FirstValue
    	Else
    		Variable = SecondValue
    	End If
    End Sub
    
    
    'Example usage
    Dim Colour
    For N = 1 To 10
    	Call ToggleVariable(Colour, "#FF0000", "#00FF00")
    	Response.Write "<font color='" & Colour & "'>" & N & "</font><br />"
    Next
    %>
    NOTE: I always prefer the Call Sub(Param1, Param2) syntax (it's easier to read), but as always you can use the standard Sub Param1, Param2 syntax if you prefer.

    This sub is also useful for toggling between True/False states, and because it modifies the variable directly (using the ByRef) it can be used for as many variables as you want at the same time (in one app I'm working on, I have 4 state variables in one loop, all toggling between states at different times). Finally, please note that because of the way that it works, you don't even need to initialise your variable with the first state value - the sub will automatically set it to the first state the first time it is called!!

    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •