开发者

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

开发者 https://www.devze.com 2023-01-19 11:46 出处:网络
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开发者_开发

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

精彩评论

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