EntityDataSource 中的默认日期时间参数

发布于 2024-09-04 15:12:26 字数 399 浏览 1 评论 0原文

我有一个 ASP.Net DetailsView,绑定到 EntityDataSource 控件。 我的 EntitySet 有一个 DateTime 属性,我想将其设置为 DateTime.Now 的默认值 我不想在 DetailsView 上显示此属性。 我想我可以在 EntityDataSource 中使用 InsertParameter,但不知道语法,也不知道这是否可能:

        <InsertParameters>
            <asp:Parameter DbType="DateTime2" DefaultValue="" />
        </InsertParameters>

我采取了正确的方法吗?

I have a ASP.Net DetailsView, bound to an EntityDataSource control.
My EntitySet has a DateTime Property that I want to set to a default value of DateTime.Now
I don't want to display this property on the DetailsView.
I figure I could use an InsertParameter in my EntityDataSource, but don't know the syntax, or whether this is possible:

        <InsertParameters>
            <asp:Parameter DbType="DateTime2" DefaultValue="" />
        </InsertParameters>

Am I taking the right approach?

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

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

发布评论

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

评论(1

无远思近则忧 2024-09-11 15:12:26

好吧,看起来不可能在 HTML 中做到这一点,但您可以在后面的代码中轻松做到这一点。
只需将 Inserting 事件处理程序附加到实体数据源,然后将 DateTime 参数设置为您需要的默认值:

    protected void edsNewsItem_Inserting(object sender, EntityDataSourceChangingEventArgs e)
    {
        var newsItem = e.Entity as NewsItem;
        if (newsItem != null)
        {
            newsItem.Date = DateTime.Now;
            newsItem.LastUpdated = DateTime.Now;
        }
    }

Well, it doesn't look like it's possible to do this in HTML, but you can do it easy in code behind.
Simply attach an Inserting event handler to your entity data source, and then set the DateTime parameter to the defaults you require:

    protected void edsNewsItem_Inserting(object sender, EntityDataSourceChangingEventArgs e)
    {
        var newsItem = e.Entity as NewsItem;
        if (newsItem != null)
        {
            newsItem.Date = DateTime.Now;
            newsItem.LastUpdated = DateTime.Now;
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文