How do I repeat html output in aspnet and c#?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Maybe is a simple question but I found difficult to find the answer.

Context:
I am creating a site where designers ONLY touch the ASPX page and I.S. touch
the code behind.

Task:
I have a simple page that list a number of offers based on info from the
system (no dabatase, no bound objects please)

Problem:
In old ASP this task it was quite simple, just create the layout once and
then you repeat it using a <% for .... %>. This gives the designer the
ability to change the entry and it will be repeated several time:

Example Old ASP:
<% for (int i = 0; i < Total; i++) { %>
<TR>
<TD>
Here goes my entry where you can design me!, number <%= i %>
</TD>
</TR>

This is easy and great, now, how can I do this on ASPNET? If I use ASPNET
tags it does not allow me to use code blocks, also, I though about creating a
usercontrol with the entry design and then dynamically addedd to a
table....mmmm... it doesn't work cause I need to register the usercontrol but
it can be 10, or event 20 times plotted on the page, cause I don't know the
amount of usercontrols until I process the page. (this solution works great
in a windows applicaiton but it seems hard stuff for ASPNET)

Hope this makes sense, is a very simple thing to do but is hard to find the
answer.

Thansk in advance
 
You have several options here :
- using Response.Write is still possible. I'm not using the intermixed
style. You may want to post the exact error. Using this in code works...
- in ASP.NET you would rather use "controls". Actually here you could have a
single asp:Table control (an HTML table) in which your code will dynamically
add lines as needed...
(you could also use DataBind even with if your data are not coming from a
DB).
- or you could use a Repeater to repeat the same HTML template for each
source line

The whole idea behind ASP.NET is to control HTML rendering through a server
side programming model that models the "objects" you'll find on your final
page client side...

http://samples.gotdotnet.com/quickstart/aspplus/doc/webdatabinding.aspx#lists
and around may help to get started with ASP.NET

Patrice
 
Forgot to mention that your designers are the ones who will make the
template.

Eliyahu

Eliyahu Goldin said:
Salvador,

You need to use a Repeater control. You will define an ItemTemplate and
databind it (I know, you asked for no bound object, but that's the way) to a
datasource. The datasource doesn't have to be a database table. It can be an
array. Have a look at ASP.NET data binding overview here:
http://support.microsoft.com/default.aspx?scid=kb;en-us;307860

Eliyahu

Salvador said:
Hi,

Maybe is a simple question but I found difficult to find the answer.

Context:
I am creating a site where designers ONLY touch the ASPX page and I.S. touch
the code behind.

Task:
I have a simple page that list a number of offers based on info from the
system (no dabatase, no bound objects please)

Problem:
In old ASP this task it was quite simple, just create the layout once and
then you repeat it using a <% for .... %>. This gives the designer the
ability to change the entry and it will be repeated several time:

Example Old ASP:
<% for (int i = 0; i < Total; i++) { %>
<TR>
<TD>
Here goes my entry where you can design me!, number <%= i %>
</TD>
</TR>

This is easy and great, now, how can I do this on ASPNET? If I use ASPNET
tags it does not allow me to use code blocks, also, I though about creating a
usercontrol with the entry design and then dynamically addedd to a
table....mmmm... it doesn't work cause I need to register the
usercontrol
 
Hi,

Maybe is a simple question but I found difficult to find the answer.

Context:
I am creating a site where designers ONLY touch the ASPX page and I.S. touch
the code behind.

Task:
I have a simple page that list a number of offers based on info from the
system (no dabatase, no bound objects please)

Problem:
In old ASP this task it was quite simple, just create the layout once and
then you repeat it using a <% for .... %>. This gives the designer the
ability to change the entry and it will be repeated several time:

Example Old ASP:
<% for (int i = 0; i < Total; i++) { %>
<TR>
<TD>
Here goes my entry where you can design me!, number <%= i %>
</TD>
</TR>

This is easy and great, now, how can I do this on ASPNET? If I use ASPNET
tags it does not allow me to use code blocks, also, I though about creating a
usercontrol with the entry design and then dynamically addedd to a
table....mmmm... it doesn't work cause I need to register the usercontrol but
it can be 10, or event 20 times plotted on the page, cause I don't know the
amount of usercontrols until I process the page. (this solution works great
in a windows applicaiton but it seems hard stuff for ASPNET)

Hope this makes sense, is a very simple thing to do but is hard to find the
answer.

Thansk in advance
Quite difficult to really separate the View from the Controller and/or
Model. .Net gives you the impression that this would be easy, but it is
only true for the most trivial cases.
I would try in order:
1. Use data binding
2. Use repeaters or other complex list controls
3. Do your own rendering replacing stuff as needed in a template
4. Use templates, but here the designers/coders are mixing.
5. Use <% %> as last resort and keep it simple
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top