Gridview header visible
-
-
Hey all I have a gridview on my page which the you can filter. This all works fine, however when your filter returns no results the whole table disappears. Is there anyway to keep the header row visible instead of the blank screen? Thanks in advance
This is how I've done it in the past: Always include one blank or dummy row at the very beginning of the gridview's datasource datatable. Then in the gridview's RowDataBound event add code to check if it is the first row, and if it is to hide it. It would look something like this:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
Select Case e.Row.RowType
Case DataControlRowType.DataRow
If e.Row.RowIndex = 0 Then e.Row.Visible = False
End Select
End SubSince the gridview has a row it will display the headers, but the row itself will be hidden.