Geeks With Blogs

News

Microsoft MVP


DZone MVB


Moderator at CodeASP.NET


Quiz Master







free counters
Free counters
Added on January 19,2012


Follow Me @vmsdurano

A bit About Me



Disclaimer
The opinions expressed herein are my own personal opinions and does not represent the opinions of my employers. Nor does it represent the opinion of my dog, because I don’t have one.


Vinz' Blog (ProudMonkey) "Code, Beer and Music ~ my way of being a programmer"

There are times that we need to set the border color of the GridView just like in my case, I was told to set the border color of GridView to a particular color instead of the default black. What I did is simply use the BorderColor property of the GridView and set it declaratively like below:

<asp:GridView ID="GridView1" runat="server" GridLines="Both" BorderColor="Red"><asp:/GridView>

Here's how it looks when we run that one in the browser.

Firefox 3.5

Safari 5

IE 8

Noticed that in IE8 it looks stranged.This is because in IE8 the declarative BorderColor attribute only adds an inline style declaration which only applies to the table itself and not on individual cells.

The Workaround

Option 1: Using CSS

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <style type="text/css">
       table.grid{
           border-collapse:collapse;
           border:solid 1px Red;
        }
        table.grid td, th{
           border:solid 1px Red;
        }

    </style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:GridView ID="GridView1" runat="server" GridLines="Both" CssClass="grid">
    </asp:GridView>
    </form>
</body>
</html>


Option 2: Adding BorderColor Attribute at the Code-Behind

protected void Page_Load(object sender, EventArgs e){

      GridView1.Attributes.Add("bordercolor","Red");

}

 

That's it! I hope someone find this post useful!

Technorati Tags: ,,
Posted on Thursday, October 7, 2010 8:38 PM ASP.NET , Tips&Tricks , GridView | Back to top


Comments on this post: Tip/Trick: Fixing GridLines Border Color in IE8

# re: Tip/Trick: Fixing GridLines Border Color in IE8
Requesting Gravatar...
This is really helpful. Thanks a lot.
Left by Shawn on Dec 13, 2011 8:33 AM

# re: Tip/Trick: Fixing GridLines Border Color in IE8
Requesting Gravatar...
I know this is kind of old, but it worked for me! Thanks!
Left by Dan on Dec 25, 2011 11:39 PM

comments powered by Disqus

Copyright © Vincent Maverick Durano | Powered by: GeeksWithBlogs.net