开发者

GridView - display '0' for all headers when empty data set

I'm using a GridView to display some ifnromation in ASP.NET. I need it to simply display 0 in the gridview fields (there's only ever one row returned) if the dataset is empty, plus of cou开发者_开发知识库rse display the headers. How do I do this?


Yes bind a dummy dataset with one row, with all zeros as fields, to the grid with zeros as the field labels. That would be the best way.


Bind your grid and add the EmptyDataTemplate like so:

<asp:GridView ID="gridview1" runat="server" ShowFooter="true">
            <Columns>
            <asp:BoundField DataField="id" HeaderText="ID field" />
            </Columns>
            <EmptyDataTemplate>put whatever you want in here</EmptyDataTemplate>
</asp:GridView>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜