Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to change a table cell's background color?

Reply
Thread Tools

How to change a table cell's background color?

 
 
HB
Guest
Posts: n/a
 
      05-06-2006
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?


 
Reply With Quote
 
 
 
 
HB
Guest
Posts: n/a
 
      05-06-2006
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?
>



 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      05-07-2006
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?
>>

>
>



 
Reply With Quote
 
HB
Guest
Posts: n/a
 
      05-07-2006
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?
>>>

>>
>>

>
>



 
Reply With Quote
 
Mark Rae
Guest
Posts: n/a
 
      05-07-2006
"HB" <> wrote in message
newsts7g.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;


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change the background image in a table cell Jim Javascript 2 07-24-2008 01:19 AM
not able to click on background tab and backgrounds in properties to change the background. rex Computer Support 2 12-06-2006 02:26 AM
Change table background based on content free4trample@yahoo.com Javascript 11 09-29-2006 01:50 AM
A Paradise DNS address change? What change? There was no change. Tony Neville NZ Computing 7 09-22-2006 01:02 PM
How can I use onclick to change a table cell background color Michael Javascript 1 05-15-2004 04:16 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57