change table cell style in vb code

K

Keith G Hicks

asp.net 2.0 using vwd

I'm trying to chagne the border of a table cell in my vb code but cannot
seem to do it. The cell has an ID of "tdAlert"

If txtAlert.Text <> "" Then
tdAlert.Style = "width: 547px; border-left-color: red;
border-bottom-color:
red; border-top-style: solid; border-top-color: red; border-right-style:
solid; border-left-style: solid; border-right-color: red;
border-bottom-style: solid;"
Else
tdAlert.Style = "width: 547px;"
End If

apparently tdAlert doesn't exist. I've saved the project thinking that maybe
intellisense would not find it if I didn't save it with the new ID but that
didnt' solve the problem. Any ideas on how this can be done? I just need a
red border around the cell under certain conditions.

Thanks,

Keith
 
A

Anthony Jones

Keith G Hicks said:
asp.net 2.0 using vwd

I'm trying to chagne the border of a table cell in my vb code but cannot
seem to do it. The cell has an ID of "tdAlert"

If txtAlert.Text <> "" Then
tdAlert.Style = "width: 547px; border-left-color: red;
border-bottom-color:
red; border-top-style: solid; border-top-color: red; border-right-style:
solid; border-left-style: solid; border-right-color: red;
border-bottom-style: solid;"
Else
tdAlert.Style = "width: 547px;"
End If

apparently tdAlert doesn't exist. I've saved the project thinking that maybe
intellisense would not find it if I didn't save it with the new ID but that
didnt' solve the problem. Any ideas on how this can be done? I just need a
red border around the cell under certain conditions.


In order to access the td as ASP.NET control it needs, in addition to an id
attribute, a runat="server" attribute. This makes it a HtmlTableCell.

You can not assign a style string directly since its an instance of
CssStyleCollection. This isn't a good approach anyway. A css class would
be better. The HtmlTableCell doesn't expose a CssClass attribute so you
need to add it via the Attributes collection.

The HtmlTableCell has a Width property so you can assign the 547px width to
that property.

Add the following mark up to your <head>:-

<style type="text/css">
td.highlight {border:1px solid red;}
</style>

Then your code becomes:-

If txtAlert.Text <> "" Then

tdTest.Attributes.Add("class", "highlight");

Else

tdTest.Attributes.Remove("class");

End If
 

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

Top