469,579 Members | 1,218 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

datagrid and border-collapse:collapse style

Hi

I need a datagrid on a page, but it is rendered with the style
"border-collapse:collapse;". I do not need this style. It interferes with
the settings in my CSS file. I tried to supress it with this code (1 line of
code):

DataGrid1.ControlStyle.Reset();

which works.
Unfortunately I need cellspacing="0"
When I set cellspacing to zero like this (2 lines of code):

DataGrid1.ControlStyle.Reset();
DataGrid1.CellSpacing = 0;

then the datagrid is rendered as a table and the
style="border-collapse:collapse;" comes back again!

How can I get rid of it?
Thanks

Vaclav

Nov 17 '05 #1
1 7277
Hello Vaclav,

I have seen this question in the group. Here is the reply from ASP.NET
Development team:

----------------------------------------------------------
No 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.CellSp acing,
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.

-------------------------------------------------

Hope it helps.

Best regards,
yhhuang
VS.NET, Visual C++
Microsoft

This posting is provided "AS IS" with no warranties, and confers no rights.
Got .Net? http://www.gotdotnet.com
--------------------
!From: "Vaclav Jedlicka" <vj*******@iol.cz>
!Subject: datagrid and border-collapse:collapse style
!Date: Thu, 26 Jun 2003 12:47:12 +0200
!Lines: 28
!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: <Od**************@tk2msftngp13.phx.gbl>
!Newsgroups: microsoft.public.dotnet.framework.aspnet
!NNTP-Posting-Host: 195.47.25.99
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:155060
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!
!Hi
!
!I need a datagrid on a page, but it is rendered with the style
!"border-collapse:collapse;". I do not need this style. It interferes with
!the settings in my CSS file. I tried to supress it with this code (1 line
of
!code):
!
!DataGrid1.ControlStyle.Reset();
!
!which works.
!Unfortunately I need cellspacing="0"
!When I set cellspacing to zero like this (2 lines of code):
!
!DataGrid1.ControlStyle.Reset();
!DataGrid1.CellSpacing = 0;
!
!then the datagrid is rendered as a table and the
!style="border-collapse:collapse;" comes back again!
!
!How can I get rid of it?
!
!
!Thanks
!
!Vaclav
!
!
!
!

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Frostillicus | last post: by
2 posts views Thread by Alvo von Cossel I | last post: by
1 post views Thread by Armin Gajda | last post: by
1 post views Thread by Coder | last post: by
2 posts views Thread by Randy | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.