Databinding

G

Guest

Hi I am confused with databinding - i have created repeaters and gridviews
and i understand that <%# Eval("Price") %> returns the value of price thats
bound, and i even understand that i can do <%#
String.Format("0:f2",Eval("Price")) %> will format my values. What i cant
understand though is how to further format things like that... for example,
if i want to write a class to convert the price to another currency i thought
i could do something like this:

<&
String.Format("{0:f2}",EuroExchange.ConvertCurrency("GBP","EUR",Eval("Price")) %>

I get a message saying the name "EuroExchange" does not exist in this
context. Why is this? how could i make a class exist in that context?

Where can i find more information on this?

Regards
Owen
 
M

Mark Rae

message
Hi Owen,
<&
String.Format("{0:f2}",EuroExchange.ConvertCurrency("GBP","EUR",Eval("Price"))
%>

I get a message saying the name "EuroExchange" does not exist in this
context. Why is this? how could i make a class exist in that context?

I may be wrong, but I'm not certain that this can be done in the way you
imagine - it would certainly never have occurred to me to try to do this
sort of thing like this, not that that necessarily carries any weight...
There are almost always at least two ways of doing things in .NET... :)

However, I try to make a rule that by the time I come to bind a data source
to a databound control the data is already "correct", and any subsequent
manipulation of that datasource is limited to formatting etc. However, as I
said, that's just me...

In order to achieve what (I think) you want here, I would do it in one of
two ways:

1) On the assumption that your underlying data is stored in an RDBMS of some
sort, I would add a currency identifier as a parameter to the query which
fetched the data and get the database to do the conversion - this would be
my preferred method.

2) If the first option weren't possible for whatever reason, I would use the
RowDataBound method of the data control to convert the currency from the
"base" currency to the "other" curency as the data was being bound to the
control.
Where can i find more information on this?

http://www.google.co.uk/search?sour...,GGLG:2006-28,GGLG:en&q=GridView+RowDataBound
 

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

Top