Block codes on ASP.NET

G

Guest

Hi,

Simple question, on normal HTML tags I can do the following
<% for (int i=0; i < Total; i++) {%>
<tr>
<td><%Response.Write (i); %></td>
</tr>
<%}%>

How can I do the same with aspnet tags? it complains when I do this
<% for (int i=0; i < Total; i++) {%>
<asp:TableRow>
<asp:TableCell><%Response.Write (i); %></asp:TableCell>
</asp:TableRow>
<%}%>

Any Ideas or workaround?
 
K

Karl Seguin

Since this is likely a simplified problem, I would recommend that you use
databinding with an repeater.

What error does it give anyways?

If it isn't a simplified problem, try doing it all programatically:

<script runat="server" language="c#">
void page_load()
{
for (int i = 0; i < Total; ++i)
{
HtmlTableRow row = new HtmlTableRow();
HtmlTableCell cell = new HtmlTableCell();
cell.InnerHtml = i.ToString(); //I think that's what it's called
row.Cells.Add(cell);
tbl.Rows.Add(row);
}
}
</script>
<asp:table id="tbl" runat="server" />

Karl
 
G

Guest

Hi,

Thanks for your answer, because we have a marketing team that only
understand HTML design and IS team that takes care of the code I was planning
to offer them the control of the HTML without touching C# code, an easy thing
to do on ASP. If I create the HTML dynamically they can not see how the table
looks like :)

Appreciate if there is a workaround, Thanks for your answer!!

--
Salvador Alvarez Patuel
Exony Ltd - London, UK


Karl Seguin said:
Since this is likely a simplified problem, I would recommend that you use
databinding with an repeater.

What error does it give anyways?

If it isn't a simplified problem, try doing it all programatically:

<script runat="server" language="c#">
void page_load()
{
for (int i = 0; i < Total; ++i)
{
HtmlTableRow row = new HtmlTableRow();
HtmlTableCell cell = new HtmlTableCell();
cell.InnerHtml = i.ToString(); //I think that's what it's called
row.Cells.Add(cell);
tbl.Rows.Add(row);
}
}
</script>
<asp:table id="tbl" runat="server" />

Karl
 
K

Kevin Spencer

Simple question, on normal HTML tags I can do the following

Well, this is a first for me. I've never known anyone to be able to do what
you've done "on normal HTML tags."
Any Ideas or workaround?

Well, you're probably not going to like this one, but I would suggest
learning something about what you're doing, rather than just doing it. The
following is a link to the freely-downloadable .Net Framework 1.1 SDK, which
contains all kinds of articles, tutorials, and sample code that you can use
to teach yourself how to, and the best part is, it's free!

http://www.microsoft.com/downloads/...A6-3647-4070-9F41-A333C6B9181D&displaylang=en

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.
 
E

Eliyahu Goldin

You don't program this way in Asp.Net. What do you want to achieve apart
from numbering table rows?

Eliyahu
 
K

Karl Seguin

The workaround, is to use a binding control, such a repeater, datalist or
datagrid.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
Salvador said:
Hi,

Thanks for your answer, because we have a marketing team that only
understand HTML design and IS team that takes care of the code I was
planning
to offer them the control of the HTML without touching C# code, an easy
thing
to do on ASP. If I create the HTML dynamically they can not see how the
table
looks like :)

Appreciate if there is a workaround, Thanks for your answer!!
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top