How to change a table cell's background color?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • HB

    How to change a table cell's background color?

    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

    #2
    Re: How to change a table cell's background color?

    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" <replywithingro up@notreal.com> wrote in message
    news:LE37g.5530 $yM.3162@tornad o.socal.rr.com. ..[color=blue]
    > 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?
    >[/color]


    Comment

    • Eliyahu Goldin

      #3
      Re: How to change a table cell's background color?

      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" <replywithingro up@notreal.com> wrote in message
      news:mv57g.5543 $yM.5352@tornad o.socal.rr.com. ..[color=blue]
      >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" <replywithingro up@notreal.com> wrote in message
      > news:LE37g.5530 $yM.3162@tornad o.socal.rr.com. ..[color=green]
      >> 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?
      >>[/color]
      >
      >[/color]


      Comment

      • HB

        #4
        Re: How to change a table cell's background color?

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


        "Eliyahu Goldin" <removemeegoldi n@monarchmed.co m> wrote in message
        news:OHAABkacGH A.4700@TK2MSFTN GP02.phx.gbl...[color=blue]
        > 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" <replywithingro up@notreal.com> wrote in message
        > news:mv57g.5543 $yM.5352@tornad o.socal.rr.com. ..[color=green]
        >>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" <replywithingro up@notreal.com> wrote in message
        >> news:LE37g.5530 $yM.3162@tornad o.socal.rr.com. ..[color=darkred]
        >>> 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?
        >>>[/color]
        >>
        >>[/color]
        >
        >[/color]


        Comment

        • Mark Rae

          #5
          Re: How to change a table cell's background color?

          "HB" <replywithingro up@notreal.com> wrote in message
          news:Pts7g.6121 $yM.5725@tornad o.socal.rr.com. ..
          [color=blue]
          > It seems there must be normal way to just reference the cell by its ID
          > name. Anyone know?[/color]

          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.Back Color = Color.Red;


          Comment

          Working...