views:

43

answers:

2

Hello all, so I have a GridView like this:

<asp:GridView ID="gv" runat="server" AutoGenerateColumns="False" GridLines="None"
    OnRowCommand="gv_RowCommand" OnRowDeleting="gv_RowDeleting" Width="100%" 
    OnPreRender="gv_PreRender">
    <Columns>
...
    <asp:TemplateField HeaderText="Temperatura">
        <ItemTemplate>
            <asp:TextBox MaxLength="10" ID="gvtxtTemp" runat="server" Text='<%# Eval("Registro3", "{0} °F")%>' />
        </ItemTemplate>
        <ControlStyle Width="100%" BackColor="Transparent" BorderStyle="None" />
    </asp:TemplateField>
...
    </Columns>
</asp:GridView>

So let's say that the value to bind is the number "10", so I would expect the output to be something like "10 °F" but instead I'm getting "10 °F °F". Why? am I doing something wrong?

I also tried doing it in the codebehind but the result was the same.

Update: Now I changed the format string to "a {0} °F" and I'm getting "a a 10 ° °F", now what's that suppose to mean?

A: 

Try this instead:

<asp:TextBox MaxLength="10" ID="gvtxtTemp" runat="server" Text='<%# string.format("{0} °F",Eval("Registro3"))%>' />
rick schott
OK, I tried your suggestion and I'm still getting the same result. I also tried Eval(...) + " ° F", and same result too.
Unlimited071
And now I tried <%# String.Concat(Eval(...), " °F")%> and still getting "10 °F °F". This is soooo weird. I changed this on other pages and I'm getting the same issue.
Unlimited071
A: 

Ok, so I finally got what I wanted, the format I used was:

<asp:TextBox MaxLength="10" ID="gvtxtTemp" runat="server" Text='<%# Eval("Registro3", "{0:#.# °F}")%>' />

and now I'm getting the desired output "10 °F", even thought the data is not a number (It's a varchar(10) field). Why did this work beat's me, but It worked, maybe some of you could tell me the reason. Anyhow thanks all for all your help!

Unlimited071
I didn't wip up a test project to verify, but I was going to suggest, {0: °F} earlier today.
rick schott