Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Creating a variable to accept Decimals.

Reply
Thread Tools

Creating a variable to accept Decimals.

 
 
Phillip Vong
Guest
Posts: n/a
 
      10-10-2006
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



 
Reply With Quote
 
 
 
 
Gozirra
Guest
Posts: n/a
 
      10-10-2006
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)

 
Reply With Quote
 
 
 
 
Phillip Vong
Guest
Posts: n/a
 
      10-10-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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)
>



 
Reply With Quote
 
Gozirra
Guest
Posts: n/a
 
      10-11-2006
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) 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)
> >


 
Reply With Quote
 
Phillip Vong
Guest
Posts: n/a
 
      10-11-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed) 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)
>> >

>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass a pointer variable to a function accept reference Louis C++ 7 10-01-2009 05:37 AM
Creating a variable name as the value of another variable. rdstevenson@hotmail.co.uk ASP General 6 10-13-2007 02:51 PM
"Variable variable name" or "variable lvalue" mfglinux Python 11 09-12-2007 03:08 AM
How to Accept Variable number of arguments ? vivekian C++ 7 11-25-2005 03:13 AM
How do I scope a variable if the variable name contains a variable? David Filmer Perl Misc 19 05-21-2004 03:55 PM



Advertisments