473,399 Members | 4,192 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,399 software developers and data experts.

Creating a variable to accept Decimals.

I'm using VS2005 and creating a simple test ASPX page in VB.

I have a simple FORMVIEW1 with a label "YTDLabel" databound to a SQL DB.
The DB datatype is set to decimal (18,2) and the value of this cell is 16.1.
Here is my simple Page_Load code and all I want it to do is see if the
decimal figure is greater than 1, if it is, then hide the YTDLabel. The
error message I'm getting from VS2005 is that
FormView1.FindControl("YTDLabel") is underlined and it says "Value fo Type
'System.Web.UI.Control' can not be converted to 'Decimal'". Can someone
help me out? I'm just a newbie trying to learn. Thanks!

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim YTDtest As Decimal
YTDtest = FormView1.FindControl("YTDLabel")

If YTDtest 0 Then
FormView1.FindControl("YTDLabel").Visible = False
End If
End Sub

Oct 10 '06 #1
4 1521
YTDtest is a Decimal variable. The returned value of FindControl is a
control object. These are obviously not the same thing. I think what
you are wanting to do is get the Text property of the control and
assign it to the YTDtest variable.

Try
YTDtest = Decimal.Parse(CType(FormView1.FindControl("YTDLabe l"),
Label).Text)

And you may not need to use FindControl. If the control is declared in
the code beind, you can access it directly.
YTDtest = Decimal.Parse(YTDLabel.Text)

Oct 10 '06 #2
Maybe I just don't understand. I tried your code this way and nothing
happend. I don't think it's test to see if the value is 0 because it's
now a text format. Am I right about that? How do you make it test to see
if the decimal value is greater than 1?

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

Dim YTDtest As Decimal

YTDtest = Decimal.Parse(CType(FormView1.FindControl("YTDLabe l"),
Label).Text)

If YTDtest 0 Then

FormView1.FindControl("YTDLabel").Visible = False

End If

End Sub


"Gozirra" <rm********@hotmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
YTDtest is a Decimal variable. The returned value of FindControl is a
control object. These are obviously not the same thing. I think what
you are wanting to do is get the Text property of the control and
assign it to the YTDtest variable.

Try
YTDtest = Decimal.Parse(CType(FormView1.FindControl("YTDLabe l"),
Label).Text)

And you may not need to use FindControl. If the control is declared in
the code beind, you can access it directly.
YTDtest = Decimal.Parse(YTDLabel.Text)

Oct 10 '06 #3
The type is a Decimal. Decimal.Parse converts the value of the labels
text property to a decimal type and assigns it to your variable. I
have tested a very simple example of this to make sure it works and
have had no problems. Can you step through the code and see what's
going on? I wonder if the FormView is causing problems. My small
sample does not use a FormView and works perfectly.

Phillip Vong wrote:
Maybe I just don't understand. I tried your code this way and nothing
happend. I don't think it's test to see if the value is 0 because it's
now a text format. Am I right about that? How do you make it test to see
if the decimal value is greater than 1?

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

Dim YTDtest As Decimal

YTDtest = Decimal.Parse(CType(FormView1.FindControl("YTDLabe l"),
Label).Text)

If YTDtest 0 Then

FormView1.FindControl("YTDLabel").Visible = False

End If

End Sub


"Gozirra" <rm********@hotmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
YTDtest is a Decimal variable. The returned value of FindControl is a
control object. These are obviously not the same thing. I think what
you are wanting to do is get the Text property of the control and
assign it to the YTDtest variable.

Try
YTDtest = Decimal.Parse(CType(FormView1.FindControl("YTDLabe l"),
Label).Text)

And you may not need to use FindControl. If the control is declared in
the code beind, you can access it directly.
YTDtest = Decimal.Parse(YTDLabel.Text)
Oct 11 '06 #4
This is what someone else told me to use and it worked. Gozirra, thanks for
your help!!!

Dim YTDLabel As Label
YTDLabel = DirectCast(FormView1.FindControl("YTDLabel"), Label)

Dim YTDtest As Decimal
YTDTest = Decimal.Parse(YTDLabel.Text)



"Gozirra" <rm********@hotmail.comwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
The type is a Decimal. Decimal.Parse converts the value of the labels
text property to a decimal type and assigns it to your variable. I
have tested a very simple example of this to make sure it works and
have had no problems. Can you step through the code and see what's
going on? I wonder if the FormView is causing problems. My small
sample does not use a FormView and works perfectly.

Phillip Vong wrote:
>Maybe I just don't understand. I tried your code this way and nothing
happend. I don't think it's test to see if the value is 0 because it's
now a text format. Am I right about that? How do you make it test to
see
if the decimal value is greater than 1?

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)

Dim YTDtest As Decimal

YTDtest = Decimal.Parse(CType(FormView1.FindControl("YTDLabe l"),
Label).Text)

If YTDtest 0 Then

FormView1.FindControl("YTDLabel").Visible = False

End If

End Sub


"Gozirra" <rm********@hotmail.comwrote in message
news:11**********************@m73g2000cwd.googleg roups.com...
YTDtest is a Decimal variable. The returned value of FindControl is a
control object. These are obviously not the same thing. I think what
you are wanting to do is get the Text property of the control and
assign it to the YTDtest variable.

Try
YTDtest = Decimal.Parse(CType(FormView1.FindControl("YTDLabe l"),
Label).Text)

And you may not need to use FindControl. If the control is declared in
the code beind, you can access it directly.
YTDtest = Decimal.Parse(YTDLabel.Text)

Oct 11 '06 #5

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

Similar topics

13
by: jenny | last post by:
Hi, I am trying to find a VB way that would create a folder on all existing drives - the folder name would be the same on each drive. ie c:\backup, d:\backup, etc. But the folders would only be...
5
by: Wing | last post by:
Hi all, I am writing a function that can change the value "Quantity" in the selected row of MS SQL table "shoppingCart", my code is showing below ...
1
by: kennethfine | last post by:
I'm transitioning from ASP development, please excuse these basic questions. One thing I did often in ASP was create a "translate" function to render one string to another, strip out excess...
12
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without...
1
by: hygum | last post by:
I've found a useful script that only accepts numbers and a point, and 3 decimals, in an input. But here in denmark we normally use comma as decimal delimiter in numbers, not the point (.) as in...
5
by: Vibhesh | last post by:
I am facing problem with TimeSpan structure when DirectX is used. Following is the sample code that causes the problem: ...
1
by: dixonjm | last post by:
Hi, I have been given a task to monitor all user behaviour on our web site, this has to include capturing all values of any control which have been changed. I really want to create a standalone...
7
by: nussu | last post by:
Hi, Plz provide me javascript : javascript for a textbox to accept the values in decimals and within range i need to enter a value in textbox like 1.03 and it should be <3 (lessthan 3). Plz...
12
by: CNiall | last post by:
I am very new to Python (I started learning it just yesterday), but I have encountered a problem. I want to make a simple script that calculates the n-th root of a given number (e.g. 4th root of...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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.