CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2005
    Posts
    71

    Question 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#?

  2. #2
    Join Date
    Aug 2004
    Posts
    191

    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.

  3. #3
    Join Date
    Sep 2005
    Posts
    71

    Thumbs up 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
  •  





Click Here to Expand Forum to Full Width

Featured