Bind() transform value problem

  • Thread starter Thread starter ibiza
  • Start date Start date
I

ibiza

Hi everybody,

Is there a way to convert a value with Bind()? I have a decimal(5,4)
data that I retrieve from DB, which represents a percent. For example,
50% is represented as 0.5000. When I bind the data to a gridview, I'd
like to see this value as "50", because what I do is a templatefield :
<edititemtemplate>
<asp:textbox text='<%#Bind("value")' runat="server" />
</edititemtemplate>

But is there a way to format the field so it multiplies by a hundred
before binding to the textbox?

Thank you!

ibiza
 
When you say Bind() do you mean DataBinder.Eval (or simply Eval() in 2.0)??

If so, you can specify a 3rd parameter

DataBinder.Eval(Container.DataItem, "value", "{0:p}")

Karl
 
well, I have now Text='Bind("value", "{0:p}")'. which multiplies the
given value by 100, but also shows a % sign...in a textbox where you
enter the percent number, as % sign is unwelcome. Is there a way to
remove it?

thanks
 
I am using asp.net 2.0, which means that Bind("value", "{0:p}") is the
same as DataBinder.Bind(Container.DataItem, "value", "{0:p}") in asp
1.x

thanks for your reply

ibiza
 
thanks Patrick.

hmmm but how can I use replace in a binding context? I mean,
Bind("value", "{0:p}") is in the aspx file (not in a class of function
full of VB.NET/C# code exclusively), embedded in a gridview
declaration. I tried Replace(Bind("value", "{0:p}") , " %", ""), but it
gives me an error. I guess it can't bind the data correctly anymore if
another function messes the process...

ibiza
 
Ibiza then do it in the codebehind
i'm sure you must be using a control
in short get the ID of that control whic will give you the "value" u need
and
do what you want to do..
Hope that helps
Patrick
 
oookay...but where can I use Bind() and Eval() in code behind ? I
thought it was only in the declaration of a gridview...can you give me
a tiny example?

thanks a lot,

ibiza
 
Back
Top