DDL 显示“真/假”;我想看看“是/否”数据以 bool 形式形成表。如何更改 DDL 的文本

发布于 2024-10-15 02:10:07 字数 588 浏览 2 评论 0原文

我有一个 DDL 显示任务是否完成。在表中它存储为 bool,所以当它出来时它是 true 或 false。我想构建我的 DDL 以在 true 时显示 yes,在 false 时显示 no。有人有任何提示吗:)这就是我到目前为止所拥有的。

 IEnumerable<SelectListItem> items =
            (from n in _db.ACTION_PLANs
                select new SelectListItem
                {
                    Selected = false,
                    Text = n.COMPLETED.Value.ToString(),
                    Value = n.COMPLETED.Value.ToString(),
                }
            ).Distinct();

        ViewData["COMPLETED"] = items;

有没有办法放置一个条件语句,以便文本根据真或假显示是或否?或者我怎样才能做到这一点。提前致谢

i have a DDL that shows if a task is completed. in the table it is stored as bool, so when it comes out it is true or false. i would like to build my DDL to show yes when true and no when false. does anyone have any hints :) this is what i have so far.

 IEnumerable<SelectListItem> items =
            (from n in _db.ACTION_PLANs
                select new SelectListItem
                {
                    Selected = false,
                    Text = n.COMPLETED.Value.ToString(),
                    Value = n.COMPLETED.Value.ToString(),
                }
            ).Distinct();

        ViewData["COMPLETED"] = items;

is there a way to put a conditional statement so that the text will display yes or no depending on the true or false? or how can i make this happen. thanks in advance

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

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

发布评论

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

评论(3

不爱素颜 2024-10-22 02:10:07

这没有本地化,但很简单

Text = n.COMPLETED ? "Yes" : "No"

this has no localization, but is simple

Text = n.COMPLETED ? "Yes" : "No"
各自安好 2024-10-22 02:10:07

试试这个:

select new SelectListItem
{
    Selected = false,
    Text = n.COMPLETED.Value ? "yes" : "no",
    Value = n.COMPLETED.Value,
}

Try this:

select new SelectListItem
{
    Selected = false,
    Text = n.COMPLETED.Value ? "yes" : "no",
    Value = n.COMPLETED.Value,
}
留蓝 2024-10-22 02:10:07

这行得通吗?

       IEnumerable<SelectListItem> items =
            (from n in _db.ACTION_PLANs
                select new SelectListItem
                {
                    Selected = false,
                    Text = n.COMPLETED.Value ? "Yes" : "No",
                    Value = n.COMPLETED.Value ? "Yes" : "No",
                }
            ).Distinct();

        ViewData["COMPLETED"] = items;

Will this work?

       IEnumerable<SelectListItem> items =
            (from n in _db.ACTION_PLANs
                select new SelectListItem
                {
                    Selected = false,
                    Text = n.COMPLETED.Value ? "Yes" : "No",
                    Value = n.COMPLETED.Value ? "Yes" : "No",
                }
            ).Distinct();

        ViewData["COMPLETED"] = items;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文