M
Matt MacDonald
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
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