Ask a Question related to ASP.NET General, Design and Development.
-
Vaclav Jedlicka #1
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
Vaclav Jedlicka Guest
-
How can I avoid border-collapse:collapse to come ...
How can I avoid border-collapse:collapse to come in style of table tag when ASP.NET DataGrid is rendered? When Datagrid is populated and rendered... -
Fontinfo expand/collapse
I added a fontinfo property to a custom control public FontInfo TitleFont { get { return _title_font; } set { _title_font = value; } } In... -
Expand and Collapse
My codebehind file contains a lot of sub's. Is there a fast way to expand and collapse them in the VisualStudio? It's really exhausting to collapse... -
asp:Table and border-collapse
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... -
Site Expand/Collapse
When I click on the expand/collapse icon of the Site Files dialogue box I no longer get a view of both the remote and local files. What happens is... -
Yan-Hong Huang[MSFT] #2
RE: datagrid and border-collapse:collapse style
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? [url]http://www.gotdotnet.com[/url]
--------------------
!From: "Vaclav Jedlicka" <vjedlicka@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: <OdZQ$B9ODHA.3144@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
!
!
!
!
Yan-Hong Huang[MSFT] Guest



Reply With Quote

