当DataSource中没有数据时DetailsView不可见

发布于 2024-09-15 10:23:53 字数 338 浏览 10 评论 0原文

即使底层数据源中没有数据,如何显示DetailsView?

问题是,当 DetailsView 不可见时,命令按钮也不可见。所以我无法将新记录插入数据库。我希望始终可见 DetailsView 并将其 DefaultMode 设置为 ReadOnly。

如果不可能,我想请求解决此问题的方法。

我想到的一种解决方法是检查数据源是否有任何记录。如果否,则以编程方式将 DefaultMode 更改为 Insert。然而这又导致了另一个问题——如何计算DataSource中的记录数。

我所有的问题都与 ASP 3.5 有关

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

顾冷 2024-09-22 10:23:53

您需要添加一个 EmptyDataTemplate:

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

You need to add an EmptyDataTemplate:

   <asp:DetailsView ID="MyDV" runat="server">
        <EmptyDataTemplate>
            <asp:Button ID="InsertButton" runat="server" CommandName="New" />
        </EmptyDataTemplate>
   </asp:DetailsView>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文