473,785 Members | 2,844 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 6639
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
2501
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
2029
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
10330
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...
1
10093
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
8976
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
7500
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
6740
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();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3654
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.