Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > DataFormatString not working in GridView

Reply
Thread Tools

DataFormatString not working in GridView

 
 
Alan Silver
Guest
Posts: n/a
 
      02-20-2006
Hello,

I have a GridView control, and am unsuccessfully trying to format a
column to show costs. The (simplified) code is as follows...

<asp:GridView ID="grdCustomers" DataSourceID="dtaCustomers"
AutoGenerateColumns="false" runat="server">
<Columns>
<asp:BoundField DataField="Total" DataFormatString="&pound;{0:F2}" />
</Columns>
</asp:GridView>

As you can see, I have set the DataFormatString to "&pound;{0:F2}",
which should give them a Pound sign, followed by the value with two
decimal places (like you would expect a cost to look).

The problem is that the numbers are not being formatted correctly. I
have things like $23.9 (where I have changed the pound sign to a dollar
sign to ensure it shows up right in Usenet). This should show as $23.90,
with the extra zero.

Any ideas? TIA


--
Alan Silver
(anything added below this line is nothing to do with me)
 
Reply With Quote
 
 
 
 
Darren Kopp
Guest
Posts: n/a
 
      02-20-2006
try DataFormatString = &pound; {0:0.00}, but what you have should
work...

HTH,
Darren Kopp
http://blog.secudocs.com/

 
Reply With Quote
 
 
 
 
Alan Silver
Guest
Posts: n/a
 
      02-20-2006
In article <(E-Mail Removed) .com>,
Darren Kopp <(E-Mail Removed)> writes
>try DataFormatString = &pound; {0:0.00}, but what you have should
>work...


Thanks for the suggestion, but that didn't work either.

It worries me when you say what I have should work!! Is there anything
else I can check to see why it isn't. Thanks again

--
Alan Silver
(anything added below this line is nothing to do with me)
 
Reply With Quote
 
Darren Kopp
Guest
Posts: n/a
 
      02-21-2006
And you said that {0:c} gave you $23.90 right?

 
Reply With Quote
 
Alan Silver
Guest
Posts: n/a
 
      02-21-2006
In article <(E-Mail Removed). com>,
Darren Kopp <(E-Mail Removed)> writes
>And you said that {0:c} gave you $23.90 right?


No, it gave $23.9

--
Alan Silver
(anything added below this line is nothing to do with me)
 
Reply With Quote
 
Darren Kopp
Guest
Posts: n/a
 
      02-21-2006
What is the datatype of "Total" (.NET data type or Database data type)

-Darren

 
Reply With Quote
 
Darren Kopp
Guest
Posts: n/a
 
      02-21-2006
What is the datatype of "Total" (.NET data type or Database data type)

-Darren

 
Reply With Quote
 
Alan Silver
Guest
Posts: n/a
 
      02-22-2006
In article <(E-Mail Removed) .com>,
Darren Kopp <(E-Mail Removed)> writes
>What is the datatype of "Total" (.NET data type or Database data type)


It's a computed field that comes from an SQL expression like...

select sum(priceeach*quantity) from siteorders...

where "priceeach" is a float and "quantity" is an int.

Thanks

--
Alan Silver
(anything added below this line is nothing to do with me)
 
Reply With Quote
 
Darren Kopp
Guest
Posts: n/a
 
      02-23-2006
Is the HtmlEncode property set to true for the field?

-Darren Kopp
http://blog.secudocs.com/

 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      02-23-2006
That's the solution. here's also an explanation:

GridView & DataFormatString in post beta 2
http://aspadvice.com/blogs/joteke/ar.../25/12871.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


"Darren Kopp" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Is the HtmlEncode property set to true for the field?
>
> -Darren Kopp
> http://blog.secudocs.com/
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataFormatString not working on a GridView DateTime column Rob Roberts ASP .Net 3 04-13-2007 07:33 PM
GridView DataFormatString not working for varchar dates ronrogell@quadax.com ASP .Net 1 08-24-2006 09:25 PM
DataFormatString in GridView does not work?? Hardy Wang ASP .Net 1 12-12-2005 03:53 PM
GridView DataFormatString not formatting AcaBrian ASP .Net Web Controls 2 12-02-2005 06:02 AM
August CTP DataFormatString in Gridview not working Gerhard Pretorius ASP .Net 3 09-22-2005 06:40 AM



Advertisments