Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > datagrid and border-collapse:collapse style

Reply
Thread Tools

datagrid and border-collapse:collapse style

 
 
Vaclav Jedlicka
Guest
Posts: n/a
 
      06-26-2003
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



 
Reply With Quote
 
 
 
 
Yan-Hong Huang[MSFT]
Guest
Posts: n/a
 
      06-30-2003
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" <(E-Mail Removed)>
!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: <OdZQ$(E-Mail Removed)>
!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
!
!
!
!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid header style inconsistent with sortable column style cedoucette@alum.rpi.edu ASP .Net 0 10-14-2005 12:13 AM
Datagrid within a Datagrid, treeview style.... Roy ASP .Net Datagrid Control 10 01-14-2005 07:31 PM
How can I save the style of a datagrid so that it appears on the automatic format to use iin another datagrid? Luis Esteban Valencia ASP .Net Datagrid Control 1 11-25-2004 08:05 AM
Need help with Style conversion from Style object to Style key/value collection. Ken Varn ASP .Net Building Controls 0 04-26-2004 07:06 PM
Convert between Windows style paths and POSIX style paths Noah Python 5 07-11-2003 09:25 PM



Advertisments