Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

change table cell style in vb code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Keith G Hicks - 19 Mar 2008 05:14 GMT
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
Anthony Jones - 19 Mar 2008 10:02 GMT
> asp.net 2.0 using vwd
>
[quoted text clipped - 15 lines]
> 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

Signature

Anthony Jones - MVP ASP/ASP.NET

Keith G Hicks - 20 Mar 2008 00:28 GMT
Thanks Anthony. That worked. But I had to do some more research because I
still was unable to access my table cell in code:

http://www.velocityreviews.com/forums/t372741-how-to-access-html-controls-fr
om-code-behind-.html (Imports
System.Web.UI.HtmlControls)

Works fine now.

Keith

> > asp.net 2.0 using vwd
> >
[quoted text clipped - 50 lines]
> --
> Anthony Jones - MVP ASP/ASP.NET
Eliyahu Goldin - 19 Mar 2008 10:05 GMT
Show how you define tdAlert in the .aspx page.

Signature

Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net

> asp.net 2.0 using vwd
>
[quoted text clipped - 22 lines]
>
> Keith

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.