Subject: question about foreach
Date: 2011-07-15 22:02:19
From: ntek designs
Source: question-foreach

im trying to change my application over to use a template engine.

before i was using a stringbuilder and building the html.  i have two tables in each of my templates that will require being created on the fly using a for each loop.

the tables are for displaying images and vehicle options..  on the first template the images table has two columns, and x amount of rows...  i did this by doing a for each loop, stepping by 2, creating a row for each iteration and creating the columns according..

the following code demonstrates what i was doing..


            If ad.HasImages Then
                With ad
                    Select Case templateID
                        Case Is = "1"
                            sb.Append("<br><br><table border='0' cellpadding='10' cellspacing='0'>")

                            For imagecounter As Integer = 1 To .ImageURLs.Count Step 2 'images are dislayed side by side so we step by 2
                                sb.Append("<tr>") 'table row start tag

                                'add column and image
                                sb.Append(String.Format("<td><img width='400' border='0' src='{0}'></td>", _
                                              .ImageURLs(imagecounter - 1))) 'append image (subtracted 1 because string array is zero based)

                                'check if there is at least one more image in the array,  if so, add the column and image
                                If imagecounter < .ImageURLs.Count Then
                                    sb.Append(String.Format("<td><img width='400' border='0' src='{0}'></td>", _
                                                .ImageURLs(imagecounter))) 'append the following image
                                End If

                                sb.Append("</tr>")  'table row end tag

                    End Select
                End With
            End If

i need to reproduce this action and perhaps even more complex ones using this template engine. is it possible? 

any examples or input would be greatly appreciated.


---------------------------------------------------------------------- Note: This question has been asked on the Q&A forum of Thang Dang's fraudulent ComponentPro brand If you purchased anything from ComponentPro, you have been scammed. Contact the payment processor who sold you the license and ask for your money back. Back to ComponentPro Q&A Forum Index