Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: Asp and tables

  1. #1
    New to the CF scene
    Join Date
    Jan 2003
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Asp and tables

    I have my page pulling from a database. I would like my table rows to alternate between grey and white. I haven't seen any code on this. I didn't know if I just use a loop and where. Any help would be great. I would also like to add a page set so only 10-15 items come in on a page similar to the board.

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    The sunny side of the Alps
    Posts
    230
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is how you can implement different colors for odd and even rows - if you would like to group it otherwise you can develop the script further.
    Code:
    ...
    set rs = conn.Execute(sSQL)
    
    i = 0
    Do While Not rs.EOF
      If i = 0 Then
        sColor = "#FFFFFF"
        i = 1
      Else
        sColor = "#C0C0C0"
        i = 0
      End If
      Response.Write "<tr><td bgcolor=" & sColor & ">TEXT</td></tr>"
      rs.MoveNext
    Loop

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    The sunny side of the Alps
    Posts
    230
    Thanks
    0
    Thanked 0 Times in 0 Posts
    And if you wan't to implement page listing you can look at http://www.aspfaq.com/show.asp?id=2120

    Bostjan

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Same thing, slightly different method:

    Code:
    <%
    Dim i, colorarray
    i = 0
    colorarray = Split("#ffffff,#cccccc",",")
    Response.Write("<table>" & vbCrLf)
    Do While Not rs.EOF
      Response.Write("<tr><td bgcolor=" & colorarray(i) & ">TEXT</td></tr>" & vbCrLf)
      rs.MoveNext
      i = ((i + 1) MOD 2)
    Loop
    Response.Write("</table>" & vbCrLf)
    %>
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #5
    New to the CF scene
    Join Date
    Jan 2003
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I must be doing something wrong...
    I have 2 pages. The page I am changing is this..
    Code:
    <!-- #include file="includes/common.asp" -->
    <% 
    
    	ProcessPage True, "Welcome to the Catalog"
    
    sub Main()
    	Dim iCategoryID, oRS
    	iCategoryID = Request.Querystring("CategoryID")
    	set oRS = getRecordset("SELECT * FROM tblItems WHERE intCategoryID = " & iCategoryID& " ORDER BY vchName;")
    	if (oRS.BOF AND oRS.EOF) Then
    		Response.write "Sorry, there are no products in this category. Please select another.<P>"    
    	Else
    		response.write "<TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=2>" & vbCrLf
    		oRS.MoveFirst
    		Do While NOT oRS.EOF
    			ShowItemDetails oRS
    			oRS.MoveNext
    		Loop
    		Response.Write "</TABLE>" & vbCrLf
    	End If
    	oRS.Close
    
     end sub
    %>

    Here is the showdetails ors page that gets called:
    Code:
    sub ShowItemDetails(oRS)   
    	dim x
    			%>
    
    
    
        <tr>
        	
    	  <td width="75%" colspan="3"><b>&nbsp;<% =oRS("vchName")%>&nbsp;<b>
    			<% if oRS("vchImageName") ="" then %>
          				<% Response.Write "<font color=red><i>No image!</font>" & vbCrLf%>
    		        <% end if %>
    			<% if oRS("vchImageName") <>"" then%> 
    				<a href="javascript: popUpimg('Test.asp?img=<% =oRS("vchImageName")%>','popup','340','375','0');void(0);"><img src="images/camera.gif" border=0></A>
    			<% end if %></b></i></td>
        </tr>
    
        <tr><td colspan=3><i><% =oRS("vchYear")%>&nbsp;<%=oRS("vchTeam")%>&nbsp;<% =oRS("vchType")%></i></td></tr>
        <tr><td  width="350" colspan="3"><%=oRS("vchDescription")%></td></tr>
        <tr><td width="50%"></td><td width="75%"></td><td width="40%"><% if oRS("intCardNumber") ="" then%><% response.write("card #")%><%=oRS("intCardNumber")%><%end if%></td></tr>
        <tr><td width="10%"></td><td width="10%"></td><td width="40%" rowspan="2"></td></tr>
       
        <tr><td colspan=3 width="40%" valign="top">
    		<table><tr><td>Price: <B><% =formatcurrency(oRS("monPrice"))%> </b></td><td>
    		<% if oRS("intInventory") = "0" then
          		Response.Write "<font color=red><i>This item is out of stock.</i></font>" & vbCrLf
          		else %>
            	<form method="GET" action="cart.asp">
    	        <input type="hidden" name="action" value="add">
    	        <input type="hidden" name="intItemID" value="<%=oRS("intItemID")%>">
    	        <p><select size="1" name="count">
            	<% for x = 1 to CInt(oRS("intInventory"))
            		Response.write"<option value=" & x & ">" & x & "</option>" & vbCrLf
              		next %>
    	        </select></td>
    		<td><input type="image" value="Submit" name="B1" src="images/buy.GIF" border=0 onclick="popUp()"> </p>
    		<input type="hidden" name="intInventory" value="<%=CInt(oRS("intInventory"))%>">
    		<input type="hidden" name="ReturnURL" value="<%= "http://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("PATH_INFO") & "?" & Request.ServerVariables("QUERY_STRING") %>">
    		</form>      
            	<% end if %>
    		</td></tr></table>   
    
       </td></tr>
       <tr><td colspan=3><p>&nbsp;<p></td></tr>    
    		<%
    end sub



    I figured part of the code goes in each page. I don't get any errors it just changes every row to the same color??
    Last edited by irisheye5; 01-21-2003 at 04:03 PM.

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yikes... fyi, there's a nice little forum feature you can use to make your code easier to read when you post... use this:

    [code]
    ' Code here
    [/code]

    I would attempt to reformat your code in order to be able to make sense of it, but I have too many other things going on.

    Hint: That looks like a mess because the formatting was lost - can you repost the code with the formatting intact?
    Last edited by whammy; 01-21-2003 at 01:16 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  

    Posting Permissions

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