asp:Table and border-collapse

Discussion in 'ASP .Net Web Controls' started by Michael Tissington, Aug 1, 2003.

  1. 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 separate?

    Thanks.

    --
    Michael Tissington
    Oaklodge Technologies
    http://www.oaklodge.com/technology
     
    Michael Tissington, Aug 1, 2003
    #1
    1. Advertising

  2. Hi Michael,

    Try:
    [C#]
    YourTable.Style["border-collapse"] = "separate";

    --
    Victor Garcia Aprea
    Microsoft MVP | ASP.NET
    Looking for insights on ASP.NET? Read my blog:
    http://obies.com/vga/blog.aspx
    To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
    and not by private mail.

    "Michael Tissington" <> wrote in message
    news:%...
    > 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 separate?
    >
    > Thanks.
    >
    > --
    > Michael Tissington
    > Oaklodge Technologies
    > http://www.oaklodge.com/technology
    >
    >
    >
     
    Victor Garcia Aprea [MVP], Aug 4, 2003
    #2
    1. Advertising

  3. I tried this and it does not help (in the Page_Load) - why is it defaulting
    to this?

    --
    Michael Tissington
    Oaklodge Technologies
    http://www.oaklodge.com/technology

    "Victor Garcia Aprea [MVP]" <> wrote in message
    news:...
    > Hi Michael,
    >
    > Try:
    > [C#]
    > YourTable.Style["border-collapse"] = "separate";
    >
    > --
    > Victor Garcia Aprea
    > Microsoft MVP | ASP.NET
    > Looking for insights on ASP.NET? Read my blog:
    > http://obies.com/vga/blog.aspx
    > To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
    > and not by private mail.
    >
    > "Michael Tissington" <> wrote in message
    > news:%...
    > > 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 separate?
    > >
    > > Thanks.
    > >
    > > --
    > > Michael Tissington
    > > Oaklodge Technologies
    > > http://www.oaklodge.com/technology
    > >
    > >
    > >

    >
    >
     
    Michael Tissington, Aug 4, 2003
    #3
  4. I tried my code and its working for me. Maybe there is something else wrong
    in your code?

    --
    Victor Garcia Aprea
    Microsoft MVP | ASP.NET
    Looking for insights on ASP.NET? Read my blog:
    http://obies.com/vga/blog.aspx
    To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
    and not by private mail.


    "Michael Tissington" <> wrote in message
    news:...
    > I tried this and it does not help (in the Page_Load) - why is it

    defaulting
    > to this?
    >
    > --
    > Michael Tissington
    > Oaklodge Technologies
    > http://www.oaklodge.com/technology
    >
    > "Victor Garcia Aprea [MVP]" <> wrote in message
    > news:...
    > > Hi Michael,
    > >
    > > Try:
    > > [C#]
    > > YourTable.Style["border-collapse"] = "separate";
    > >
    > > --
    > > Victor Garcia Aprea
    > > Microsoft MVP | ASP.NET
    > > Looking for insights on ASP.NET? Read my blog:
    > > http://obies.com/vga/blog.aspx
    > > To contact me remove 'NOSPAM'. Please post all questions to the

    newsgroup
    > > and not by private mail.
    > >
    > > "Michael Tissington" <> wrote in message
    > > news:%...
    > > > 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 separate?
    > > >
    > > > Thanks.
    > > >
    > > > --
    > > > Michael Tissington
    > > > Oaklodge Technologies
    > > > http://www.oaklodge.com/technology
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Victor Garcia Aprea [MVP], Aug 5, 2003
    #4
  5. Hello Michael,

    Victor is right and I have also tested it on my side.

    By the way, in order to stop the System.Web.UI.WebControls.Table() class from rendering the "border-collapse:collapse"
    style property in the <TABLE> tag, we could set CellSpacing to something other than 0.

    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.CellSpacing, 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.

    Thanks very much for participating the community.

    Best regards,
    Yanhong Huang
    Microsoft Online Partner Support

    Get Secure! - www.microsoft.com/security
    This posting is provided "AS IS" with no warranties, and confers no rights.

    --------------------
    !From: "Michael Tissington" <>
    !References: <#> <>
    !Subject: Re: asp:Table and border-collapse
    !Date: Mon, 4 Aug 2003 07:03:41 -0700
    !Lines: 44
    !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: <>
    !Newsgroups:
    microsoft.public.dotnet.framework.aspnet.buildingcontrols,microsoft.public.dotnet.framework.aspnet.webcontrols
    !NNTP-Posting-Host: antelope.oaklodge.com 63.67.71.5
    !Path: cpmsftngxa06.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08.phx.gbl!
    TK2MSFTNGP10.phx.gbl
    !Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet.webcontrols:13640
    microsoft.public.dotnet.framework.aspnet.buildingcontrols:6909
    !X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    !
    !I tried this and it does not help (in the Page_Load) - why is it defaulting
    !to this?
    !
    !--
    !Michael Tissington
    !Oaklodge Technologies
    !http://www.oaklodge.com/technology
    !
    !"Victor Garcia Aprea [MVP]" <> wrote in message
    !news:...
    !> Hi Michael,
    !>
    !> Try:
    !> [C#]
    !> YourTable.Style["border-collapse"] = "separate";
    !>
    !> --
    !> Victor Garcia Aprea
    !> Microsoft MVP | ASP.NET
    !> Looking for insights on ASP.NET? Read my blog:
    !> http://obies.com/vga/blog.aspx
    !> To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
    !> and not by private mail.
    !>
    !> "Michael Tissington" <> wrote in message
    !> news:%...
    !> > 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 separate?
    !> >
    !> > Thanks.
    !> >
    !> > --
    !> > Michael Tissington
    !> > Oaklodge Technologies
    !> > http://www.oaklodge.com/technology
    !> >
    !> >
    !> >
    !>
    !>
    !
    !
    !
     
    Yan-Hong Huang[MSFT], Aug 5, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vaclav Jedlicka

    datagrid and border-collapse:collapse style

    Vaclav Jedlicka, Jun 26, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    5,951
    Yan-Hong Huang[MSFT]
    Jun 30, 2003
  2. phl
    Replies:
    1
    Views:
    4,357
    Martin Jay
    Jun 8, 2006
  3. Michael Tissington

    asp:Table and border-collapse

    Michael Tissington, Aug 1, 2003, in forum: ASP .Net Building Controls
    Replies:
    4
    Views:
    253
    Michael Tissington
    Aug 5, 2003
  4. VVSRKS

    How can I avoid border-collapse:collapse to come ...

    VVSRKS, Sep 16, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    202
    VVSRKS
    Sep 16, 2004
  5. Tom Castiglia

    Why does Gridview ALWAYS emit style="border-collapse: collapse;"

    Tom Castiglia, Jun 4, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    2,019
    Tom Castiglia
    Jun 9, 2006
Loading...

Share This Page