473,770 Members | 6,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataFormatStrin g in GridView does not work??

Hi, I have a GridView control in my web form (ASP.NET 2.0)

<asp:GridView ID="gvReport" runat="server" AllowSorting="T rue"
AutoGenerateCol umns="False"
Width="100%">
<HeaderStyle CssClass="ItemC aption" />
<RowStyle CssClass="Line" />
<AlternatingRow Style CssClass="AltLi ne" />
<Columns>
<asp:BoundFie ld DataField="Item Name" HeaderText="Ite m
Name" SortExpression= "ItemName" />
<asp:BoundFie ld DataField="Purc haseDate"
DataFormatStrin g="{0:F}" HeaderText="Pur chase Date"
SortExpression= "PurchaseDa te" />
<asp:BoundFie ld DataField="Cost "
DataFormatStrin g="{0:c}" HeaderText="Cos t"
SortExpression= "Cost" />
<asp:BoundFie ld DataField="Unit Price"
DataFormatStrin g="{0:c}" HeaderText="Uni t Price"
SortExpression= "UnitPrice" />
<asp:BoundFie ld DataField="Quan tity"
HeaderText="Qua ntity" SortExpression= "Quantity" />
</Columns>
</asp:GridView>

I want to format the output of "Cost" and "UnitPrice" columns to display in
currency format, thus I added DataFormatStrin g="{0:c}" to column
declaration. Does it suppose to show the result of these two columns like
"$1,000.00" , "$0.99"? But actually what I can get is all "1000.0000" ,
"0.9900"!
I created a dummy function in this web page to run string s =
cost.ToString(" C"); the output is currect.
Anything wrong with GridView?
Regards
Hardy
Dec 12 '05 #1
1 6638
OK, I found solution, I must set HtmlEncode="fal se" to enable formatting.
"Hardy Wang" <ha*******@hotm ail.com> wrote in message
news:eq******** *****@TK2MSFTNG P10.phx.gbl...
Hi, I have a GridView control in my web form (ASP.NET 2.0)

<asp:GridView ID="gvReport" runat="server" AllowSorting="T rue"
AutoGenerateCol umns="False"
Width="100%">
<HeaderStyle CssClass="ItemC aption" />
<RowStyle CssClass="Line" />
<AlternatingRow Style CssClass="AltLi ne" />
<Columns>
<asp:BoundFie ld DataField="Item Name" HeaderText="Ite m
Name" SortExpression= "ItemName" />
<asp:BoundFie ld DataField="Purc haseDate"
DataFormatStrin g="{0:F}" HeaderText="Pur chase Date"
SortExpression= "PurchaseDa te" />
<asp:BoundFie ld DataField="Cost "
DataFormatStrin g="{0:c}" HeaderText="Cos t"
SortExpression= "Cost" />
<asp:BoundFie ld DataField="Unit Price"
DataFormatStrin g="{0:c}" HeaderText="Uni t Price"
SortExpression= "UnitPrice" />
<asp:BoundFie ld DataField="Quan tity"
HeaderText="Qua ntity" SortExpression= "Quantity" />
</Columns>
</asp:GridView>

I want to format the output of "Cost" and "UnitPrice" columns to display
in currency format, thus I added DataFormatStrin g="{0:c}" to column
declaration. Does it suppose to show the result of these two columns like
"$1,000.00" , "$0.99"? But actually what I can get is all "1000.0000" ,
"0.9900"!
I created a dummy function in this web page to run string s =
cost.ToString(" C"); the output is currect.
Anything wrong with GridView?
Regards
Hardy

Dec 12 '05 #2

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

Similar topics

1
2611
by: frank | last post by:
I am using the DataFormatString property on BoundColumn objects in a DataGrid, but they don't seem to work for some reason. I copied them straight from another DataGrid where they work fine, but for some reason they have no effect in the following grid. The two that don't work are DataFormatString="{0:dd-MM-yyyy}" and DataFormatString="{0:C}". The code is below. Anyone got any ideas what the problem is?
4
2500
by: Amelyan | last post by:
When I try to apply {0:d} to date or {0:c} to number (for currency), my GridView doesn't apply the format. It still shows DateTime as it comes from database with time and currency as just a number without $ sign. Formatting in my DataGrids still works just fine. Is anyone else experiencing the same problem? Thanks, -Boris
0
888
by: Henry Lee | last post by:
hi , I want to insert image for select button in gridview object. However , no matter how hard I try to change on selectimageurl property, the image just does not show , it only shows "Select Text". Any idea ? Thanks, Henry
3
2028
by: Mark Leistner | last post by:
I am having problems getting a gridview to bind to custom objects under any non-full trust level. I created a test project to verify what I am seeing isn't a side effect of other code in my project and I get the same errors there: Exception Details: System.Security.SecurityException: That assembly does not allow partially trusted callers.
1
5946
by: needin4mation | last post by:
Not sure what I'm doing wrong here. I have a gridview and a detailsview. The detailsview is set to insert by default. When I insert data the detailsview it works. The data goes in the database. The gridview on the page, however, never refreshes to show the new row. The sql for the gridview defaults to a LIKE % and when the page first loads I can see all the records. If after I try an edit a gridview record and delete or cancel, then...
2
9211
by: Beemer Biker | last post by:
Cant believe I spent 4 hours trying to figure out why only the first grid in my new multiview shows up and the other grids are invisible in the other views I just added. The database tables were not populated except for the table I had in the first view! INCREDIBLE: All that data I saw during design, and assumed it came from the database, was just bill gates made up data that the designer needed so you could see what you were doing. So...
2
2454
by: cmrhema | last post by:
hello, i am new to asp.net. i am trying to do a simple application of adding,inserting and deleting rows in gridview. i am using C#.net and javascript. My edit/update works but i have problems in deleting the rows in the datagrid. i have used command fields(properties-columns) edit,update,cancel and delete commands. i changed it to template field. both are as buttons. ihave changed the id of Delete command to btDelete. The...
0
1830
by: cmrhema | last post by:
Hello, I am having a problem with GRIDVIEW IN C#. The following code updates only the alternate rows. When i use the edit button all the cells does get converted to textboxes thereafter when i click on the updated button the alternate rows do not enter the if loop mentioned in the code. So only the rows 1,3,5,7... gets updated whereas the rows which bear the even no.s 2,4,6,8.. does not get updated. And the smart thing is neither does...
6
4538
by: Steve Harclerode | last post by:
Hi, I'm trying to get my DataGrid to show headers and footers when no rows are returned from the datasource. Below is code that shows the first TemplateField. Is there an easy way to get at least the footer to show? I want to be able to insert a new row using the footer. Thanks... <asp:GridView ID="gvMaterials" runat="server" AutoGenerateColumns="False" DataSourceID="dsMaterials" ShowFooter="True" Width="100%"
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10230
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10058
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10004
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7416
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.