asp:Table and border-collapse

  • Thread starter Michael Tissington
  • Start date
M

Michael Tissington

I'm using the asp:Table control and it insists on adding the style
"border-collapse:collapse;"

Any idea how I can make it use the default of separate?

Thanks.
 
V

Victor Garcia Aprea [MVP]

Hi Michael,

Try:
[C#]
YourTable.Style["border-collapse"] = "separate";

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
and not by private mail.
 
M

Michael Tissington

I tried this and it does not help (in the Page_Load) - why is it defaulting
to this?

--
Michael Tissington
Oaklodge Technologies
http://www.oaklodge.com/technology

Victor Garcia Aprea said:
Hi Michael,

Try:
[C#]
YourTable.Style["border-collapse"] = "separate";

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
and not by private mail.

Michael Tissington said:
I'm using the asp:Table control and it insists on adding the style
"border-collapse:collapse;"

Any idea how I can make it use the default of separate?

Thanks.
 
V

Victor Garcia Aprea [MVP]

I tried my code and its working for me. Maybe there is something else wrong
in your code?

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
and not by private mail.


Michael Tissington said:
I tried this and it does not help (in the Page_Load) - why is it defaulting
to this?

--
Michael Tissington
Oaklodge Technologies
http://www.oaklodge.com/technology

Victor Garcia Aprea said:
Hi Michael,

Try:
[C#]
YourTable.Style["border-collapse"] = "separate";

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
and not by private mail.

Michael Tissington said:
I'm using the asp:Table control and it insists on adding the style
"border-collapse:collapse;"

Any idea how I can make it use the default of separate?

Thanks.
 
M

Michael Tissington

Thanks for the detailed answer.

--
Michael Tissington
Oaklodge Technologies
http://www.oaklodge.com/technology

Yan-Hong Huang said:
Hello Michael,

Victor is right and I have also tested it on my side.

By the way, in order to stop the System.Web.UI.WebControls.Table() class
from rendering the "border-collapse:collapse"
style property in the <TABLE> tag, we could set CellSpacing to something other than 0.

There isn't a way to get rid of border-collapse if you set CellSpacing to 0.

Perhaps there should have been a way to override this behavior. Tables
with cellspacing=0 with the borders collapsed don't
look like they have really 0 cellspacing (visually), because each cell has
a border. Therefore to make it appear that there is
absolutely no space between cells, we add this style attribute.

Here's what you should do:
1. Write a MyTable control deriving from Table
2. In there override CreateControlStyle to plug in a derived style
protected override Style CreateControlStyle() {
return new MyTableStyle(ViewState);
}
3. Write the MyTableStyle class deriving from TableStyle like so:

public class MyTableStyle : TableStyle {
private bool _rendering;

public override int CellSpacing {
get {
if (_rendering) {
return -1;
}
return base.CellSpacing;
}
set {
base.CellSpacing = value;
}
}

public override void AddAttributesToRender(HtmlTextWriter writer, WebControl owner) {
try {

_rendering = true;
base.AddAttributesToRender(writer, owner);
}
finally {
_rendering = false;
}
int n = CellSpacing;
if (n >= 0) {
writer.AddAttribute(HtmlTextWriterAttribute.CellSpacing, n.ToString(CultureInfo.InvariantCulture));
}
}
}

That should do the trick... of course this is email code based on memory
of the code, so it might need small modifications to
fully work.

Thanks very much for participating the community.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
!Subject: Re: asp:Table and border-collapse
!Date: Mon, 4 Aug 2003 07:03:41 -0700
!Lines: 44
!X-Priority: 3
!X-MSMail-Priority: Normal
!X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
!X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
!Message-ID: <[email protected]>
!Newsgroups:
microsoft.public.dotnet.framework.aspnet.buildingcontrols,microsoft.public.d
otnet.framework.aspnet.webcontrols
!NNTP-Posting-Host: antelope.oaklodge.com 63.67.71.5
!Path: cpmsftngxa06.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
..phx.gbl!
TK2MSFTNGP10.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet.webcontrols:13640
microsoft.public.dotnet.framework.aspnet.buildingcontrols:6909
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
!
!I tried this and it does not help (in the Page_Load) - why is it defaulting
!to this?
!
!--
!Michael Tissington
!Oaklodge Technologies
!http://www.oaklodge.com/technology
!
!!> Hi Michael,
!>
!> Try:
!> [C#]
!> YourTable.Style["border-collapse"] = "separate";
!>
!> --
!> Victor Garcia Aprea
!> Microsoft MVP | ASP.NET
!> Looking for insights on ASP.NET? Read my blog:
!> http://obies.com/vga/blog.aspx
!> To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
!> and not by private mail.
!>
!> !> > I'm using the asp:Table control and it insists on adding the style
!> > "border-collapse:collapse;"
!> >
!> > Any idea how I can make it use the default of separate?
!> >
!> > Thanks.
!> >
!> > --
!> > Michael Tissington
!> > Oaklodge Technologies
!> > http://www.oaklodge.com/technology
!> >
!> >
!> >
!>
!>
!
!
!
 

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,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top