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