macros14
asked on
Repeater Control Cast from type 'DBNull' to type 'Currency' is not valid
Hi I am trying to format a number on a aspx page in a reapeter item template.
<%# formatnumber(DataBinder.Ev al(Contain er.DataIte m, "TOTAL_SQ_FOOTAGE"),0) %>
The problem is there are times when the value is null, and then the page bombs.
Cast from type 'DBNull' to type 'Currency' is not valid.
How do I put an if statement for checking for dbnull.value?? I need an if statement in other place as well.
<%# formatnumber(DataBinder.Ev
The problem is there are times when the value is null, and then the page bombs.
Cast from type 'DBNull' to type 'Currency' is not valid.
How do I put an if statement for checking for dbnull.value?? I need an if statement in other place as well.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ooops, forgetting the double quote
<%# DataBinder.Eval(Container. DataItem, "TOTAL_SQ_FOOTAGE", "{0:C}") %>
<%# DataBinder.Eval(Container.
Try this
Public Function IsSetNull() As Boolean
Return Me.IsNull(Me.tablename.Col umn)
End Function
Public Sub SetNull()
Me(Me.tablename.Column) = System.Convert.DBNull
End Sub
Regards
skumar
Public Function IsSetNull() As Boolean
Return Me.IsNull(Me.tablename.Col
End Function
Public Sub SetNull()
Me(Me.tablename.Column) = System.Convert.DBNull
End Sub
Regards
skumar
you could also set the default value in the db to something more realistic like 0.00 - think about this - it will speed up the processing so you dont have to execute those extra lines of code - makes a difference if there are lots of requests.
I'm assuming that you created that formatnumber method right? Why don't you check the value of the parameter that you are passing to your method first (whether it is null or not) before doing any formatting on it. if it is null then just return a 0 value or whatever.
assuming your method looks something like this:
public string formatnumber(string value, int number)
{
if(value == null)
return "0"; //or something else
//your code for formatting the value
}
-bele04-