Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DetailsView is not visible when there is no data in DataSource

What to do to show DetailsView even when there is no data in underlying datasource?

The problem is that when DetailsView is not visible, the command buttons are also not visible. So I can not insert a new record to a database. I would like to have always visible DetailsView with its DefaultMode set to ReadOnly.

If it is not possible I would like to ask for an workaround for this problem.

One workaround which I have on my mind is to check if datasource have any records. If no then programmaticaly change DefaultMode to Insert. However this causes another problem - how to count the number of records in DataSource.

All my problems are related to the ASP 3.5

like image 695
Wodzu Avatar asked Aug 20 '10 12:08

Wodzu


1 Answers

You need to add an EmptyDataTemplate:

   <asp:DetailsView ID="MyDV" runat="server">
        <EmptyDataTemplate>
            <asp:Button ID="InsertButton" runat="server" CommandName="New" />
        </EmptyDataTemplate>
   </asp:DetailsView>
like image 101
Ben Robinson Avatar answered Sep 30 '22 16:09

Ben Robinson