Wodzu
Wodzu

Reputation: 6979

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

Upvotes: 7

Views: 6576

Answers (1)

Coding Flow
Coding Flow

Reputation: 21881

You need to add an EmptyDataTemplate:

   <asp:DetailsView ID="MyDV" runat="server">
        <EmptyDataTemplate>
            <asp:Button ID="InsertButton" runat="server" CommandName="New" />
        </EmptyDataTemplate>
   </asp:DetailsView>

Upvotes: 12

Related Questions