You can't convert null to decimal; you need to check for null first. I don't
know what the VB.Net code should look like, but in C# you could do this.
Label myLabel = (Label) fvDeposits.FinControl("MyTotal");
Decimal myDecimal;
myDecimal = myLabel.Text == null ? Decimal.MinValue : (Decimal)
myLabel.Text;
or you can do:
Label myLabel = (Label) fvDeposits.FinControl("MyTotal");
Decimal myDecimal;
if(!String.IsNullOrEmpty(myLabel.Text))
{
myDecimal = (Decimal) myLabel.Text;
}
else
{
myDecimal = Decimal.MinValue;
}
Regards;
Brian K. Williams
"VB Programmer" <do**********@somewhere.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>I have a FormView control, "fvDeposits", which has 1 databound label in it,
called "MyTotal". If the label is blank/no data this line of code gets the
error "Run-time exception thrown : System.ArgumentNullException - Object
cannot be null"
CType(CType(Me.fvDeposits.FindControl("MyTotal"), Label).Text, Decimal)
Any ideas how I can get around this?
Thanks!