How to change a table cell's background color?

  • Thread starter Thread starter HB
  • Start date Start date
H

HB

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?
 
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.
 
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
 
It seems there must be normal way to just reference the cell by its ID name.
Anyone know?
 
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;
 

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

Ask a Question

Back
Top