2

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.

MPelletier
  • 16,256
  • 15
  • 86
  • 137
David Adlington
  • 666
  • 4
  • 15
  • 27

3 Answers3

3

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.

ciencia
  • 456
  • 4
  • 11
TStamper
  • 30,098
  • 10
  • 66
  • 73
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.

Emad Mokhtar
  • 3,237
  • 5
  • 31
  • 49
0

There is an easier, cleaner way in mark-up (so it doesn't matter if you are using VB or C#): Simply set the GridView's ShowHeaderWhenEmpty property to true. :)

Ref. See top answer here: GridView - Show headers on empty data source

However, that does not display the footer and Microsoft, in its infinite wisdom, somehow did not see fit to add the obvious equivalent ShowFooterWhenEmpty property :( So, I'm still looking into that.

NOTE: The following, existing GridView property is not sufficient for an empty dataset: Set the ShowFooter property to true.*

To display the footer, we have the sproc (stored procedure), which populates our grid, return a row of nulls, or mainly just nulls, when the SQL SELECT concerned found no matches. Works well. ;)

Zeek2
  • 386
  • 4
  • 8