Ok, I keep running into this problem
In my aspx I am calling a simple function.
But the problem is, that the function is either, string, integer, etc.
If there's null's in the data, the function explodes because it's set to a string or integer, etc.
How can I make the function accept both a null, and another data type so that I can
write some if then's to do different things if it is null or another data type.
Here is the code to give you an idea
#
# .aspx code
#
# <%# GetRatingFormat(Container.DataItem("Rating") %>
#
#
# .vb code
#
# Function GetRatingFormat(ByVal UserRating As Decimal) As String
#
# If IsNothing(UserRating) Or IsDBNull(UserRating) Then
# Return "Not Yet Rated"
# Else
# Return Format(UserRating, "0.0") & "%"
# End If
#
#
# End Function
#
#
#
UserRating needs to accept both null and decimal
any help would be greatly appreciated
1 reply to this topic
#1
Posted 19 October 2010 - 01:26 PM
|
|
|
#2
Posted 21 October 2010 - 03:48 AM
String class has the NullOrEmpty Static method use it before you update Db about the rating is made(4 Stars etc)
in C# that would be:
in C# that would be:
public String FormatRating(Decimal numRated){
return String.IsNullorEmpty(numRated.ToString())?"Not Rated Yet":numRated.ToString("0%");
}
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









