是否可以从 DetailsView 中的 CheckboxField 中提取选中状态?
最初我有一个 TemplateField ,其中有一个复选框,但我无法使用
Checked='<%# (bool)Bind("FieldName") %>
或
Checked='<%# (bool)Eval("FieldName") %>
它不断抛出无效的强制转换异常来设置复选框值。数据库中的字段是设置为 1 或 0 的位字段。
我尝试切换到复选框字段,但因为我的更新代码位于代码隐藏中,而不是使用数据源中的 updatecommand 参数,所以我似乎无法从中检索值要传递给我的业务逻辑的 CheckBoxField。
任何人都可以告诉我如何从详细信息视图中的 CheckBox 字段中检索值吗?
Originally I had a TemplateField with a CheckBox in it but I couldn't set the checkbox Value using
Checked='<%# (bool)Bind("FieldName") %>
or
Checked='<%# (bool)Eval("FieldName") %>
It kept throwing an invalid cast exception. The field in the database is a bit field set to 1 or 0.
I tried switching to a checkbox field but because my update code is in the codebehind instead of using the updatecommand parameters in a datasource I can't seem to retrieve the value from the CheckBoxField to pass to my business logic.
Can any one point me on how to retrieve the value from the CheckBoxfield in a detailsview?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你不能从 int 转换为 bool。尝试
Convert.ToBoolean(Eval("FieldName"))
不确定是否可以像这样使用Eval
,但这就是一般想法。You can't cast from int to bool. Try
Convert.ToBoolean(Eval("FieldName"))
Not sure if you can useEval
like that though, but that's the general idea.我认为您需要对数据库中的值使用
ToString()
,因为 HTML 正在查找 True 或 False,而不是 1 或 0。I think that you need to use
ToString()
on the value from the database, since the HTML is looking for True or False, not 1 or 0.您可以使用
然后在后面的代码中设置它吗?解决方案似乎有效此处
Could you use
Then set it from there in code behind. Solution seemed to work here