ASP.NET Remove GridView Border From EmptyDataTemplate

by Bill Beckelman 2/8/2008 6:34:24 PM

I like to put a border around my gridviews. However, when they are empty, the border doesn't look good. It took some searching to find a good way to not show the border. Its been a while, so I am not sure which forum I found the answer in. I improved upon the answer though by adding the code to a class, so I thought I would share it.

image

image

I added the code below to a class that contains some other gridview stuff:

    Public Shared Sub RemoveBorders(ByVal gridView As GridView)
        If gridView.Rows.Count = 0 Then
            gridView.BorderStyle = BorderStyle.None
        Else
            gridView.BorderStyle = BorderStyle.Solid
        End If
    End Sub

Then in the RowDataBound Event of all of my gridviews that I want to remove the border from, I add the following code (SortGridView is the name of my class):

    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
        'remove its border if it is empty.
        SortGridView.RemoveBorders(sender)
    End Sub

Hopefully, I can save somebody some time looking through the forums.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.NET

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

7/3/2008 4:41:06 PM



Powered by BlogEngine.NET 1.3.0.29
Theme by Mads Kristensen

About the author

Name of author Bill Beckelman
I live and work in South Jordan, Utah

E-mail me Send mail

Calendar

<<  July 2008  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

Pages

    Recent comments

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2008

    Sign in