实体框架默认值
我正在使用带有DetailsView 的EntityDataSource。
插入新项目时,如何使可为空的布尔字段之一默认为“已选中”?
<asp:CheckBoxField DataField="MyBoolColumn" HeaderText="Bool" />
我尝试在数据库中设置默认值,在实体属性中设置默认值,并在实体的构造函数中设置默认值:
public partial class MyEntity
{
public MyEntity()
{
this._MyBoolColumn= true;
}
I am using an EntityDataSource with a DetailsView.
How can I get one of the nullable boolean fields to default to 'checked' when inserting new items?
<asp:CheckBoxField DataField="MyBoolColumn" HeaderText="Bool" />
I have tried setting a default value in the DB, a default value in the properties of the entity and by setting a default value in the constructor of the Entity:
public partial class MyEntity
{
public MyEntity()
{
this._MyBoolColumn= true;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望选中此字段,则必须在 ASP.NET 页面中默认选中它,或者在后面的代码中设置它(处理
Inserting
和Updating
事件数据源),因为您的任何更改都会被页面中未选中的复选框中的 false 覆盖。但是,当页面上不可见时,将任何复选框默认设置为 true 是很奇怪的,而且对用户非常不友好。If you want this field to be checked you must make it checked by default in your ASP.NET page or set it in the code behind (handle
Inserting
andUpdating
events in the data source) because any your change is overwritten by false from unchecked checkbox in the page. But setting any checkbox by default as true when it is not visible on the page is strange and very user unfriendly.