Bind() transform value problem

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
 
K

Karl Seguin [MVP]

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
 
I

ibiza

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

ibiza

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
 
I

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
 
P

Patrick.O.Ige

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
 
I

ibiza

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
 
Joined
Dec 19, 2008
Messages
1
Reaction score
0
May be a little late but

Better late than never I guess. This worked for me in ASP.NET 3.5

SelectedValue='<%# CheckIfExists(Eval("RequestTypeID")) %>'>

In CodeBehind:

Code:
    public String CheckIfExists(object str)
    {
        String test;
        test = "hello world";
        return test;
    }

In aspx:
Code:
<asp:DropDownList ID="id" runat="server" DataValueField="value" DataSourceID="sdsRequestTypes"  [B]SelectedValue='<%# CheckIfExists(Eval("RequestTypeID")) %>'[/B]></asp:DropDownList>
 

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

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top