|
-
October 13th, 2005, 02:15 PM
#1
HTML Writing with ASP.NET
In classic ASP we would have an HTML page and an ASP page.
In HTML page we would have a place holder something like this:
Code:
<form>
<table>
<!-- Values -->
</table>
</form>
In ASP page we would replace the "<!-- Values -->" to the rest of the table information, something like this:
Code:
stringTable = "<tr><td>" & tableRS("FieldName") & "</td></tr>"
strOutPutHTML = Replace(strOutPutHTML , "<!-- Values -->", stringTable)
response.write(strOutPutHTML)
How can we acomplish this in ASP.NET code behind using C#?
-
October 13th, 2005, 05:05 PM
#2
Re: HTML Writing with ASP.NET
In ASP.NET, everything is handled with objects in the code-behind. Your example would be easy to do with a DataGrid, like so:
in the aspx HTML section:
Code:
<asp:DataGrid ID="dgResults" runat="server">
<Columns>
<asp:BoundColumn DataField="FieldName"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
in the code-behind page (in the Page Load event for example):
Code:
// omitted: code for obtaining tableRS
dgResults.DataSource = tableRS;
dgResults.DataBind();
There are many options for things like this. If you want more control over your table, you can use a Table webcontrol and in the code you add TableRow objects to it and TableCell objects to the rows. For example:
Code:
private void loadTable()
{
for (int i = 0; i < 10; i++)
{
TableRow row = new TableRow();
for (int j = 0; j < 5; j++)
{
TableCell cell = new TableCell();
cell.Text = i.ToString() + ", " + j.ToString();
row.Cells.Add(cell);
}
myTable.Rows.Add(row);
}
}
would give you a 5x10 table with the row number and the column number in each cell.
-
October 14th, 2005, 09:35 AM
#3
Re: HTML Writing with ASP.NET
Thanks. I appreciate the help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|