Show header / footer when Gridview is empty VB.net

I understand that there is a solution for this, but I'm struggling to convert it to VB correctly :(

I managed to get a cascading set of drop-down lists with data based on the results of others that I really liked.

However, due to the message back, the grid will disappear until the second value is selected and looks terrible

In any case, a header is allowed inside VB if there is no data in the form of a grid?

Thank you very much in advance.

+2
gridview postback
Jun 02 '09 at 15:30
source share
2 answers

Yes, there is a way that can be done manually, here is the code that does it all in C # Example , just use the converter and it will pass it to you in VB

or follow these examples SO GridView - Show headers on an empty data source.

+3
Jun 02 '09 at 15:58
source share

You have 2 ways to do this:

1 - simulate 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 - create an empty data set and bind it to 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 method, because the Binding empty DataSet has some problems.

+2
May 7 '12 at 19:20
source share



All Articles