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">
    <tr>
    <td id="cellMyCell">word</td>
    </tr>
    </table>

    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
    1. Advertising

  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" <> wrote in message
    news:LE37g.5530$...
    > So I have a table in ASP.NET
    >
    > <table runat="server" id="tblMyTable">
    > <tr>
    > <td id="cellMyCell">word</td>
    > </tr>
    > </table>
    >
    > 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
    #2
    1. Advertising

  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

    "HB" <> wrote in message
    news:mv57g.5543$...
    >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" <> wrote in message
    > news:LE37g.5530$...
    >> So I have a table in ASP.NET
    >>
    >> <table runat="server" id="tblMyTable">
    >> <tr>
    >> <td id="cellMyCell">word</td>
    >> </tr>
    >> </table>
    >>
    >> How do I reference the cell "cellMyCell" from the Vb.NET 1.1 code-behind
    >> to change the background color of the cell?
    >>

    >
    >
     
    Eliyahu Goldin, May 7, 2006
    #3
  4. HB

    HB Guest

    It seems there must be normal way to just reference the cell by its ID name.
    Anyone know?


    "Eliyahu Goldin" <> wrote in message
    news:...
    > 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
    >
    > "HB" <> wrote in message
    > news:mv57g.5543$...
    >>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" <> wrote in message
    >> news:LE37g.5530$...
    >>> So I have a table in ASP.NET
    >>>
    >>> <table runat="server" id="tblMyTable">
    >>> <tr>
    >>> <td id="cellMyCell">word</td>
    >>> </tr>
    >>> </table>
    >>>
    >>> 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 7, 2006
    #4
  5. HB

    Mark Rae Guest

    "HB" <> wrote in message
    news:pts7g.6121$...

    > It seems there must be normal way to just reference the cell by its ID
    > name. Anyone know?


    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
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thanks
    Replies:
    1
    Views:
    607
    Thanks
    Feb 8, 2004
  2. RJ
    Replies:
    1
    Views:
    261
    Eliyahu Goldin
    Feb 17, 2005
  3. Michael
    Replies:
    1
    Views:
    196
    Woody
    May 15, 2004
  4. Arthur Shapiro
    Replies:
    29
    Views:
    350
    Arthur Shapiro
    Jan 2, 2005
  5. Jim
    Replies:
    2
    Views:
    177
Loading...

Share This Page