Show Header/Footer when Gridview is Blank VB.net

烈酒焚心 提交于 2019-12-08 01:50:51

问题


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.


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




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



来源:https://stackoverflow.com/questions/940234/show-header-footer-when-gridview-is-blank-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!