473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

DataFormatString not working in GridView

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)
Feb 20 '06 #1
12 6504
try DataFormatString = &pound; {0:0.00}, but what you have should
work...

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

Feb 20 '06 #2
In article <11**********************@g47g2000cwa.googlegroups .com>,
Darren Kopp <da********@gmail.com> 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)
Feb 20 '06 #3
And you said that {0:c} gave you $23.90 right?

Feb 21 '06 #4
In article <11*********************@o13g2000cwo.googlegroups. com>,
Darren Kopp <da********@gmail.com> 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)
Feb 21 '06 #5
What is the datatype of "Total" (.NET data type or Database data type)

-Darren

Feb 21 '06 #6
What is the datatype of "Total" (.NET data type or Database data type)

-Darren

Feb 21 '06 #7
In article <11**********************@o13g2000cwo.googlegroups .com>,
Darren Kopp <da********@gmail.com> 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)
Feb 22 '06 #8
Is the HtmlEncode property set to true for the field?

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

Feb 23 '06 #9
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" <da********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Is the HtmlEncode property set to true for the field?

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

Feb 23 '06 #10
Ah ha! That fixed it. Thanks for the reply.

In article <#A**************@TK2MSFTNGP09.phx.gbl>, Teemu Keiski
<jo****@aspalliance.com> writes
That's the solution. here's also an explanation:

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


--
Alan Silver
(anything added below this line is nothing to do with me)
Feb 23 '06 #11
Cool, glad to hear that you got it working.

Happy .NETing
Darren Kopp,
http://blog.secudocs.com/

Feb 23 '06 #12

Your DataFormatString should work just set HtmlEncode to false
*** Sent via Developersdex http://www.developersdex.com ***
Mar 10 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Gerhard Pretorius | last post by:
Since installing the VS.NET August CTP the DataFormatString of the BoundField in the Gridview does not work. Runtime v2.0.50727. <asp:BoundField DataField="Event_Date"...
1
by: Gerhard Pretorius | last post by:
I am reposting this..hoping someone (from Microsoft) can confirm this at least as a problem: Since installing the VS.NET August CTP the DataFormatString of the BoundField in the Gridview and...
2
by: Jon | last post by:
Hi All, I have a column in my GridView with DataFormatString="{0:dd/MM/YYYY HH:mm}" HtmlEncode="False" Still the date formats as 2005-11-08T20:48:03 Any ideas? I'm using latest full release...
1
by: Hardy Wang | last post by:
Hi, I have a GridView control in my web form (ASP.NET 2.0) <asp:GridView ID="gvReport" runat="server" AllowSorting="True" AutoGenerateColumns="False" Width="100%"> <HeaderStyle...
2
by: Rob Roberts | last post by:
I have a GridView that is bound to a collection of DateTimes (i.e. - Collection<DateTime>). I have a BoundField in the GridView, and its DataField is set to the DateTime's Date property, and the...
4
by: Eamonn | last post by:
Hi I am running Microsoft Visual Studio 2005 Team Edition Version 8.0.50727.42. I am adding columns to a GridView at runtime. When I add a BoundField that will contain DateTime data I want to...
2
by: pgonzo | last post by:
In my initial tests with the GridView control, I cannot understand why the DataFormatString attribute has no affect on the column formatting. The 'creation_date' field is being reported as "3/30/02...
3
by: bsm | last post by:
I have created GridView and assign Datasource at RunTime. I need to format one Column which will have the following data. Start_date Want to Format as...
5
by: Tim Mackey | last post by:
hi, with a derived DataGrid control, i can override the CreateColumnSet method and scan into the DataGridColumns and set the DataFormatString, e.g. leave out the time part of a DateTime value. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.