Board index » Web Programming » change table cell style in vb code

change table cell style in vb code

Web Programming9
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


-
 

Re:change table cell style in vb code



"Keith G Hicks" <krh@comcast.net>wrote in message

Quote
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







--

Anthony Jones - MVP ASP/ASP.NET





-

Re:change table cell style in vb code

Show how you define tdAlert in the .aspx page.



--

Eliyahu Goldin,

Software Developer

Microsoft MVP [ASP.NET]

msmvps.com/blogs/egoldin">msmvps.com/blogs/egoldin

usableasp.net">usableasp.net





"Keith G Hicks" <krh@comcast.net>wrote in message

Quote
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









-

Re:change table cell style in vb code

Thanks Anthony. That worked. But I had to do some more research because I

still was unable to access my table cell in code:



www.velocityreviews.com/forums/t372741-how-to-access-html-controls-fr">www.velocityreviews.com/forums/t372741-how-to-access-html-controls-fr

om-code-behind-.html (Imports

System.Web.UI.HtmlControls)



Works fine now.



Keith



"Anthony Jones" <Ant@yadayadayada.com>wrote in message

Quote


"Keith G Hicks" <krh@comcast.net>wrote in message

news:OuMuNcXiIHA.4344@TK2MSFTNGP03.phx.gbl...

>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







--

Anthony Jones - MVP ASP/ASP.NET









-