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
You need to add an EmptyDataTemplate:
<asp:DetailsView ID="MyDV" runat="server">
<EmptyDataTemplate>
<asp:Button ID="InsertButton" runat="server" CommandName="New" />
</EmptyDataTemplate>
</asp:DetailsView>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With