从 SPFieldBoolean 获取值
如何从 SPFieldBoolean 对象获取值?我是简单地把它转换为布尔值还是需要对它做进一步的事情?
我在 ItemAdded 事件期间从 properties.ListItem["fieldname"]
在 EventReceiver 类中获取它。
如果该字段有可能不存在(并且为空),我该如何检查?
How do I get the value from a SPFieldBoolean object? Do I simply cast it to a boolean or do I need to do something further with it?
I am fetching it in an EventReceiver class during an ItemAdded event from properties.ListItem["fieldname"]
.
If there is a chance the field might not exist (and be null), how do I check for that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该值已经是一个
bool
,您只需对其进行类型转换即可。所有字段都以其本机值类型提供值 - 另请参阅 SPField.FieldValueType 属性,为您提供实际类型,以防您需要在运行时检查它。要确保该字段包含在列表中,只需使用 SPFieldCollection.ContainsField 方法。
The value is already a
bool
, you just need to type-cast it. All fields provide values in their native value-type — see also SPField.FieldValueType property that gives you the actual type in case you need to inspect it on runtime.To make sure the field is contained in the list, just use the SPFieldCollection.ContainsField method on your list's
Fields
collection.