Convertig Problem Double.Parse

L

lvpaul

Hello !

I have an asp.net-datagrid.

On the itemdatabound-event I want to check a column.

Values of the columns are e.g.

153,57 €
200,10 €
n. def. (not defined, because of division 0)
20,33 €

I want to convert the cell-value to a double value:

double.parse don´t work because of the "€" or "n. def".

An exception is the consequence.

Do you have any idea ?

Thanks
aapaul
 
K

Karl Seguin [MVP]

why not simply check the value first, you say you are already in the
ItemDataBound event, what do you currently have?



--
http://www.openmymind.net/



Hello !

I have an asp.net-datagrid.

On the itemdatabound-event I want to check a column.

Values of the columns are e.g.

153,57 ?
200,10 ?
n. def. (not defined, because of division 0)
20,33 ?

I want to convert the cell-value to a double value:

double.parse don´t work because of the "?" or "n. def".

An exception is the consequence.

Do you have any idea ?

Thanks
aapaul
 
K

Karl Seguin [MVP]

In the ItemDataBound event, do something like:

If (e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem) Then
dim dv as DataRowView = ctype(e.Item.DataItem, DataRowView)
if (dv("SomeValue") = "n") then
e.Item.Background = Color.Red
end if
End If


Here I'm casting DataItem to a DataRowView which assums you are binding to a
dataset/datatable or data view...you can use DataBinder.Eval() instead..

KArl
 
L

lvpaul

Thanks KArl !

I want to check if
dv("SomeValue") < 0 (then backcolor red)

dv could be e.g.

204.34 €
n. def.
400,12 €

double.parse makes an exception if it isnt a real number !

Do I have to build a function with try catch ?

Paul
 
K

Karl Seguin [MVP]

There are a number of ways, a function that catches certain exceptions is
certainly a way to go....probably the way I'd go

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/


Thanks KArl !

I want to check if
dv("SomeValue") < 0 (then backcolor red)

dv could be e.g.

204.34 ?
n. def.
400,12 ?

double.parse makes an exception if it isnt a real number !

Do I have to build a function with try catch ?

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top