gpt4 book ai didi

c# - 将 FormView 中的列表绑定(bind)到 ASP.net webforms 中的模型

转载 作者:太空宇宙 更新时间:2023-11-03 14:32:00 24 4
gpt4 key购买 nike

对于大型填充表单,我使用 asp.net FormView 将魔术数据绑定(bind)到我的模型。在这个模型中,我有一个名为 Rides 的属性(如下所示),它公开了一个列表,我显然不想完全替换它。所以我把它设为只读。

但是,这样我就不能再使用数据绑定(bind)功能了。这个问题有通用的解决方案吗?

public IList<Ride> Rides
{
get
{
if (this._rides == null)
{
this._rides = new List<Ride>();
}

return this._rides;
}
}

最佳答案

您仍然可以使用数据绑定(bind),而不是 <%# Bind("PropertyName")%> 使用 <%# Eval("PropertyName")%>,因为 Bind 通常用于 2 种方式绑定(bind),而 Eval 通常用于评估底层数据源,当您也有 setter 时,Bind 会很方便。希望这能提供足够的启发,您会发现它很有帮助。

关于c# - 将 FormView 中的列表绑定(bind)到 ASP.net webforms 中的模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2385319/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com