0

I've added a caption to multiple gridviews to show data from multiple views in my database. I need the captions to be visible even if there are no rows in the gridviews.

<asp:GridView ID="GridViewH1" runat="server" AutoGenerateColumns="False" DataSourceID="Holding1" ShowHeader="False" GridLines="None" Caption="- Holding 1 -" >
    <Columns>
        <asp:BoundField DataField="POS_NUM" HeaderText="POS_NUM" SortExpression="POS_NUM" ItemStyle-CssClass="gridview" />
        <asp:BoundField DataField="RAILCAR" HeaderText="RAILCAR" SortExpression="RAILCAR" />
    </Columns>
</asp:GridView>
barkerlao
  • 1
  • 2
  • Maybe this could help you if you are using ASP.NET 4 http://stackoverflow.com/questions/354369/gridview-show-headers-on-empty-data-source – Enrique Zavaleta Apr 29 '15 at 22:34

2 Answers2

0

There is a MultiView control for this kind of behaviour.

Put the GridView in a View of the MultiView and in the other the fallback text. This is pseudo-code that guides you, look up actual ASP.NET specs online:

<asp:MultiView ...>
    <asp:View ...>
        <asp:GridView .... />
    </asp:View>
    <asp:View ...>
        No data available.
    </asp:View>
</asp:MultiView ...>

You can then switch between the two View from the code behind with a very easy if() statement. Mind you have to COUNT(*) the number of expected results beforehand to switch.

pid
  • 11,472
  • 6
  • 34
  • 63
  • Thanks for the potential workaround. I have 8 gridviews and might have to scale that up in the future. I'm looking for something a little lighter, if possible. – barkerlao Apr 29 '15 at 21:18
0

Might not consider this relevant... However, did you try the EmptyDataTemplate on them? You could simply input your caption as the EmptyDataTemplate's message.

If the gridviews have a datasource attached, but no data was returned to it... the EmptyDataTemplate should be the active template.

    <asp:GridView ID="GridView1" runat="server" DataSourceID="dsPartTypes">
        <EmptyDataTemplate>
            No Data Found For GridView1!
        </EmptyDataTemplate>
    </asp:GridView>

Hopefully this was helpful!

Jmnstr
  • 80
  • 13