How to change a table cell's background color?

Discussion in 'ASP .Net' started by HB, May 6, 2006.

  1. HB

    HB Guest

    So I have a table in ASP.NET

    <table runat="server" id="tblMyTable">
    <td id="cellMyCell">word</td>

    How do I reference the cell "cellMyCell" from the Vb.NET 1.1 code-behind to
    change the background color of the cell?
    HB, May 6, 2006
    1. Advertisements

  2. HB

    HB Guest

    I forgot to add "without referencing row or cell numbers". I want to do it
    by names, but the Rows(x).Cells(x) stuff just wants numbers. Yeah, I
    could use an enum list but I'd like to know how to do this by "id" name.
    HB, May 6, 2006
    1. Advertisements

  3. Write a little utility method that will take the cell id as a parameter and
    loop through the Rows and Cells collections. Likely, you can use the
    FindControl method to find a cell within a row.

    Eliyahu Goldin, May 7, 2006
  4. HB

    HB Guest

    It seems there must be normal way to just reference the cell by its ID name.
    Anyone know?
    HB, May 7, 2006
  5. HB

    Mark Rae Guest

    1) Make sure your <td /> includes the runat=server tag

    2) Declare your tablecell object server-side - can't remember exactly how to
    do it in VB.NET, but in C# it's

    protected HtmlTableCell cellMyCell;

    3) When you want to change the background colour, do something like:

    cellMyCell.BackColor = Color.Red;
    Mark Rae, May 7, 2006
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.