Show Header/Footer when Gridview is Blank VB.net
Solution 1
Yes there is a way that can be done manually, here is the code that does it all in C# Example, just use a converter and it'll give it to you in VB
or follow these examples SO GridView - Show headers on empty data source.
Solution 2
You have 2 ways to do it:
1-By simulate the Input Fields inside
<asp:GridView ID="GridView1" runat="server">
<EmptyDataTemplate>
<tr>
<td>
First Cell
</td>
<td>
Second Cell
</td>
<tb>
Third Cell
</tb>
</tr>
</EmptyDataTemplate>
</asp:GridView>
2-Is to create Empty DataSet and Bind it to the GirdView.
If ds.Tables(0).Rows.Count > 0 Then
grd_codes.DataSource = ds
grd_codes.DataMember = ds.Tables(0).TableName
grd_codes.DataBind()
Else
Try
If ds.Tables(0).Rows.Count = 0 Then
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow())
grd_codes.DataSource = ds
grd_codes.DataBind()
Dim columnCount As Integer = grd_codes.Rows(0).Cells.Count
grd_codes.Rows(0).Cells.Clear()
grd_codes.Rows(0).Cells.Add(New TableCell)
grd_codes.Rows(0).Cells(0).ColumnSpan = columnCount
grd_codes.Rows(0).Cells(0).Text = "No Records Found."
End If
I prefer the first way because Binding empty DataSet has some problems.
Comments
-
David Adlington almost 2 years
I realise there is a solution for this but I am struggling to get it to convert to VB correctly :(
I have managed to get a cascading set of dropdowns with data based upon each others results which I was really pleased with.
However due to the post back the grid will disappear until the second value is selected and looks awful
Is there anyway within VB to allow the header to stick around if there is no data within the grid view?
Many thanks in advance.