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.
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
As pointed out by Tilo in the comments I changed from the OnRowDataBound event to the Databound Event of the Gridview.
Then in the DataBound 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_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)
SortGridView.RemoveBorders(sender)
End Sub
Hopefully, I can save somebody some time looking through the forums.