1

I'm trying to loop through a data set on the server-side (not a problem) and dynamically render HTML based on the items in the dataset (super basic stuff). Here's the simplified HTML:

<div>item title</div>
<div>item date</div>
<div>item summary</div>

I have 10 items being returned on the back-end, so I'd like to write out 10 iterations of the HTML above. I know this is super basic stuff, but I'd like to do this in ASP.NET without 1) embedding HTML in the C# code 2) embedding C# in the ASPX code

Is this possible? What's the best way to do this? I'm also not using MVC, so please keep that in mind. Thank you.

2
  • It also seems you are generating a list, so I'd suggest using a ul with li wrapping each title, date & summary group. Commented May 13, 2014 at 23:34
  • I was just using div's for simplicity. I'm actually using ul/li, I just don't want to embed that HTML in the C# code. Commented May 14, 2014 at 13:36

1 Answer 1

3

I would consider using a Repeater for this

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater(v=vs.110).aspx

It's a control designed for repeating arbitrary html based on the content of a data source

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

3 Comments

I'll look into that. Does Repeater have to use a table? If so, that wouldn't be an option for me.
It does not depend on a table. It works with any html
Just used it. Exactly what I needed. Thanks!

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.