Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Formview Null Values

2 views
Skip to first unread message

Matt MacDonald

unread,
Apr 25, 2008, 12:15:35 PM4/25/08
to
Hi all,
I'm having an issue that's driving me crazy. I have a datatable that I
need to display all the information for on a page. So, instead of manually
coding every single column to a label, I decided it would be easier and
safer to use a formview to display it all, bound to an objectdatasource.
Sounds simple enough. The problem is that many of my fields could
potentially have null values, which produces an error similar to the
following when the formview is databound.

Conversion from type 'DBNull' to type 'Integer' is not valid.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Conversion from type
'DBNull' to type 'Integer' is not valid.

Source Error:

Line 3122: Get
Line 3123: Try
Line 3124: Return
CType(Me(Me.tableMFT_Products.CaloriesFromFatPercColumn),Integer)
Line 3125: Catch e As Global.System.InvalidCastException
Line 3126: Throw New
Global.System.Data.StrongTypingException("The value for column
'CaloriesFromFatPerc' in table 'MFT_Products' is DBNull.", e)


So now I'm back to having to hand check every field for nulls on the
databound event, which really isn't saving me any time. My whole reason for
using the formview was to be able to use the templates to have some control
on the way the data displayed. In a gridview or other databound controls,
the framework automatically ignores null values. Is there a way to make the
formview behave similarly?

Thanks,
Matt


Stan

unread,
Apr 26, 2008, 6:00:10 AM4/26/08
to

FormView is normally just as tolerant of null values as the other data
control types you mention. The exception is being thrown by what looks
like hand-written code to convert the field to an integer.

Matt MacDonald

unread,
Apr 28, 2008, 10:32:59 AM4/28/08
to
I wish it were, but all I'm doing is attaching my datasource to the formview
and running it. I'm not doing anything in the code behind, and while the
type of that column is integer, it's all being handled from the dataset. No
manual code has been written.

"Stan" <goo...@philphall.me.uk> wrote in message
news:61bfaa60-a002-4db6...@p25g2000hsf.googlegroups.com...

0 new messages