How to change a table cell's background color?

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?
 
H

HB

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.
 
E

Eliyahu Goldin

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
 
H

HB

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

Mark Rae

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top