1

Im a VB.NET beginnger, can anyone tell me how I can dynamically add a div table row or how I can loop a section of html? thanks.

3
  • ASP.Net, or some kind of screen scraping? And if asp.net, what point in the page lifecycle are we talking about? Some more context would really be appreciated. Commented May 29, 2009 at 13:57
  • At Page Load. I want to create a row of input boxes for each additional customer. I then want to fix an id at the end of each input box ie CustomerFullName1,CustomerDOB1,CustomerFullName2,CustomerDOB2, etc. Commented May 29, 2009 at 14:02
  • I pass the number of additional customers at the page creation. Commented May 29, 2009 at 14:03

1 Answer 1

1

I'm making a few assumptions about what your doing (such as you're using ASP.Net) but you can use the Repeater control to loop a section of HTML.

<asp:Repeater ID="myRepeater" runat="server">
    <ItemTemplate>
           <div>What you want to loop here</div>
    </ItemTemplate>
</asp:Repeater>

But of course you'll have to databind the repeater for it to loop through the items that it's databound to. You could also do an inline loop:

<% for (int i = 0; i < 5; i++)
   { %>
           <div>Something repeated here</div>
<% } %>

You'll have to put the for loop into VB syntax of course.

Sign up to request clarification or add additional context in comments.

2 Comments

Brilliant, thanks. I will go for the inline loop, but is there a way to pull in a declared value, declared in the vb code file? ie for i = 0 to TotalPeople
Just put a property in the code behind of the page and then you can access that property like normal from the inline loop (this.MyProperty)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.