473,406 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Question: Referencing Formview label when no data is present

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!

Oct 22 '07 #1
1 1197
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!

Nov 7 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: sck10 | last post by:
Hello, I am pulling data from a SQL Server table. One field that is (varchar 4000) is used to show notes. I am using a FormView for showing and editing the data. When the form is in Item...
0
by: Metal2You | last post by:
I'm working on an ASP.NET 2.0 application in Visual Studio 2005 that accesses a Sybase database back end. We're using Sybase SQL Anywhere 9.0.2.3228. I have installed and registered the Sybase...
8
by: BB | last post by:
Hi, I am using FormView Contol, TextBox (Hidden ) and Submit button whose caption is "View Page" in my aspx page. Here is what I am tryin to do.When page loads I generate dynamic url in text box...
2
by: rodchar | last post by:
hey all, i'm trying to bind my dataset to a formview but i get a message that says: Conversion from type 'DBNull' to type 'Boolean' is not valid. in order to fix this do i have to specify false...
0
by: ThePurpleCat | last post by:
Hi, I'm a newbie to ASP.NET programming but not to Visual Studio. I'm having trouble getting my Master-Details page to work. I have a page enabled GridView which is linked to a FormView control...
3
by: J055 | last post by:
Hi I have a PlaceHolder control inside a FormView EditItemTemplate: <asp:PlaceHolder ID="phResponseText" runat="server"> <tr> <td> <asp:Label ID="lblResponseText"...
1
by: Trev | last post by:
Hi, I'm hoping that someone in this group can shed some light on an issue I'm having with a Formview. I have a Web User Control (.ascx) with a Formview. The Formview contains 2 Multiviews,...
8
by: =?Utf-8?B?QXNo?= | last post by:
Hi, I have an object, for example User. User contains various properties which i have been able to bind to successfully using wizards and the form view. However if the class User has a property...
2
by: Steve Richter | last post by:
can I align the items in the formview so that all the labels have the same width and all the textboxes are aligned one under the other? ( as if the formview was a table with two columns ) ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.