FormView ConvertEmptyStringToNull和绑定 [英] FormView ConvertEmptyStringToNull and binding

查看:88
本文介绍了FormView ConvertEmptyStringToNull和绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有ObjectDataSource的FormView,并使用<%#Bind("WhateverProp")%>进行绑定-我的所有可空列都返回了其中类型的默认值.

I'm using a FormView with an ObjectDataSource and binding using <%# Bind("WhateverProp") %> - and all of my nullable columns are coming back with default values of the type in them.

似乎FormView对象没有其他绑定容器那样具有ConvertEmtpyStringToNull属性.我发现有文章暗示这是VS 2005/.Net 2.0中的错误-但看不到任何关于分辨率的说法.

It appears that the FormView object doesn't have a ConvertEmtpyStringToNull property like the other binding containers do. I've found articles suggesting that this was a bug in VS 2005 / .Net 2.0 - but don't see any saying what the resolution was.

在不重新捕获ODS_Inserting事件中的所有字段的情况下,有人对我如何解决此问题有任何建议吗?我宁愿不必编写代码来重新绑定表单上的所有绑定字段,而只需测试是否为空.

Does anyone have any suggestions as to how I can work around this without just re-capturing all of the fields in the ODS_Inserting event? I'd rather not have to write code to re-bind all of my bound fields on the form just to test for nulls.

推荐答案

也很努力.对于下拉列表,我这样做:

Struggled with it too. For a dropdownlist, I do that:

AppendDataBoundItems="true"


<asp:ListItem Text="" Value=""></asp:ListItem>

对于我的ObjectDataSource,即使我的UpdateMethod接受单个参数,即实体,我也为实体的每个可空字段添加更新参数,并将其转换为NULL

For my ObjectDataSource, even thoug my UpdateMethod takes a single parameter, the entity, I add Update params for each Nullable Field of the Entity with convert to NULL

<UpdateParameters>
    <asp:Parameter Name="No_Empl_Ferme" Type="Int32" ConvertEmptyStringToNull="true" />
</UpdateParameters>

我对插入"也做同样的事情.

I do the same for the Insert.

工作正常.

这篇关于FormView ConvertEmptyStringToNull和绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆