473,503 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7588
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
29005
by: Frostillicus | last post by:
I work with Interwoven TeamSite in an environment where I do not have access to customise the default stylesheet, so the only option available to me is to specify an additional stylesheet wherein I...
0
1380
by: TusharP | last post by:
Hi Friends, I have one form having border style none. (Form have irregular shape) This form has number of Dropdown, Textbox and Labels. When Minimized button I resize form to some small value....
2
5614
by: Alvo von Cossel I | last post by:
hi, sorry about the first message; i accidentally clicked post. anyway, i want to make a modern looking app like quicktime that has not got that bar at the top with the title in it and the...
0
1061
by: Job Lot | last post by:
How can I make border of Panel control look similar to xp style textbox border style?
1
4189
by: Patrick | last post by:
Hello, I want to change the border of an asp-dropdownlist via C#. With ddl.CssClass = "empty"; I want to change the border of the DDL to red, but it works only in Firefox not in Internet...
1
15314
by: Armin Gajda | last post by:
Hi, I have the following problem: An input field get a border assigned by a style class (e.g. 2px solid red). When the field gets the focus, we set the border to green. element.style.border...
1
1225
by: Coder | last post by:
Is there a way to change a forms border style at run time?
1
1345
by: Mark Rae | last post by:
Hi, Have been modifying a piece of JavaScript I found on the net which completely prevents the Google AutoFill Toolbar from doing its stuff... Got that working now but, while I was debugging it,...
2
8176
by: Randy | last post by:
I'm trying to loop through all of the textboxes on my form and change some of their properties. I'm stuck on changing the border style to none. Here is my code: Dim c As Control For Each c In...
2
1606
by: DAXU | last post by:
Hi, What I found is that when my form set border style to none, I can't right click and close the program as I can when the border is set to fixed single. (i.e., by right click the program in...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7322
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7451
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4667
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.