By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,358 Members | 2,811 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,358 IT Pros & Developers. It's quick & easy.

Write HTML in run time using C#

P: n/a
Yiu
Here is my code:

private static ArrayList info=new ArrayList();
private Label[] label;

private void Page_Load(object sender, System.EventArgs e)
{
label=new Label[info.Count];

Response.Write("<table width=75%border=1>");
for(int cnt=info.Count;cnt>0;cnt--)
{
Response.Write("<tr>");
Response.Write("<td>");
label[cnt-1]=new Label();
label[cnt-1].Text=(String)info[cnt-1];
Page.Controls.Add(label[cnt-1]);
Response.Write("</td>");
Response.Write("</tr>");
}
Response.Write("</table>");
}
public static void setInfo(String s)
{
info.Add(s);
}

I want to create a new line between each label in run time, but i
cannot do this to create new line between label when use the code
above, have any good suggestion for me to solve this problem?
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On your line Response.Write("</table>");
Change to
Response.Write("</table><br>");

On 5 Mar 2004 23:46:49 -0800, bi********@yahoo.com.hk (Yiu) wrote:
Here is my code:

private static ArrayList info=new ArrayList();
private Label[] label;

private void Page_Load(object sender, System.EventArgs e)
{
label=new Label[info.Count];

Response.Write("<table width=75%border=1>");
for(int cnt=info.Count;cnt>0;cnt--)
{
Response.Write("<tr>");
Response.Write("<td>");
label[cnt-1]=new Label();
label[cnt-1].Text=(String)info[cnt-1];
Page.Controls.Add(label[cnt-1]);
Response.Write("</td>");
Response.Write("</tr>");
}
Response.Write("</table>");
}
public static void setInfo(String s)
{
info.Add(s);
}

I want to create a new line between each label in run time, but i
cannot do this to create new line between label when use the code
above, have any good suggestion for me to solve this problem?


Nov 18 '05 #2

P: n/a
Hi,
I want to create a new line between each label in run time, but i
cannot do this to create new line between label when use the code
above, have any good suggestion for me to solve this problem?


You could insert a blank row between each label

Response.Write("<tr><td>&nbsp;</td></tr>");

or use a CSS class to control the height of each table cell or the
label itself (labels get rendered as spans)

Regards
Charlie
Nov 18 '05 #3

P: n/a
Yiu
Below is my new code:
for(int cnt=info.Count;cnt>0;cnt--)
{
label[cnt-1]=new Label();
label[cnt-1].Text=(String)info[cnt-1];
Page.Controls.Add(label[cnt-1]);
Page.Response.Write("<tr><td>&nbsp;</td></tr>");
}

But have something wrong in the output, the <tr><td>&nbsp;</td></tr>
not print between the label, it print at the head of the HTML.Why?Have
solution?
<span>Free</span><span>Science Museum</span> is my Label output.

Below is my HTML output after add Label use the code above:
<tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>ShowInformation</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form name="Form1" method="post" action="ShowInformation.aspx"
id="Form1">
<input type="hidden" name="__VIEWSTATE"
value="dDwtNTMwNzcxMzI0Ozs+XUGdiuz4iPEe85152UYL3O0 Fa+A=" />

<FONT face="新細明體">
<input type="submit" name="BackButton" value="Back"
id="BackButton" style="height:32px;width:64px;Z-INDEX: 101; LEFT:
24px; POSITION: absolute; TOP: 288px" /></FONT></form>
</body>
</HTML>
<span>Free</span><span>Science Museum</span>
Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.