About Response.Write problem

Y

Yiu

Below is my 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+XUGdiuz4iPEe85152UYL3O0Fa+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>
 
C

Charlie

Try this:

Add an ASP table to your form in design mode like this...

<asp:Table id="Table1" runat="server"></asp:Table>

....and then add the following code to the Page_Load. It's not the most
efficient/elegant code but it will do what I think you want it to do.

for (int row = 1; row <= 5; row++)
{
// Add menu item
TableRow tableRow = new TableRow();
TableCell tableCell = new TableCell();
Label label = new Label();
label.Text = "menu item";
tableCell.Controls.Add(label);
tableRow.Controls.Add(tableCell);
Table1.Controls.Add(tableRow);

// Add spacer
TableRow tableRowSpacer = new TableRow();
TableCell tableCellSpacer = new TableCell();
Label labelSpacer = new Label();
labelSpacer.Text = "&nbsp;";
tableCellSpacer.Controls.Add(labelSpacer);
tableRowSpacer.Controls.Add(tableCellSpacer);
Table1.Controls.Add(tableRowSpacer);
}
 

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

Top