datagrid and border-collapse:collapse style

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. Fontinfo expand/collapse
      I added a fontinfo property to a custom control public FontInfo TitleFont { get { return _title_font; } set { _title_font = value; } } In...
    3. 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...
    4. 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...
    5. 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...
  3. #2

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139