473,383 Members | 1,853 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,383 software developers and data experts.

GridView and Formatting

Why is it that when I setup a BoundField Column and set the DataFormatString
property to {0:C} I get everything in 100.0000 format instead of 100.00?

Thanks in advance,

Victor
Jun 21 '06 #1
8 1381
{0:c}

will get you 100.00
"Victor Rodriguez" <la*******@newsgroups.nospam> wrote in message
news:Om**************@TK2MSFTNGP02.phx.gbl...
Why is it that when I setup a BoundField Column and set the
DataFormatString property to {0:C} I get everything in 100.0000 format
instead of 100.00?

Thanks in advance,

Victor

Jun 21 '06 #2
I've tried both ways and only by creating a fieldtemplate and on the binding
using <%# bind("FieldName","{0:c} %> works but not the other way.

Victor
"CSharpGuy" <CS*******@gmail.com> wrote in message
news:e5**************@TK2MSFTNGP02.phx.gbl...
{0:c}

will get you 100.00
"Victor Rodriguez" <la*******@newsgroups.nospam> wrote in message
news:Om**************@TK2MSFTNGP02.phx.gbl...
Why is it that when I setup a BoundField Column and set the
DataFormatString property to {0:C} I get everything in 100.0000 format
instead of 100.00?

Thanks in advance,

Victor


Jun 21 '06 #3
Hi Victor,

Thank you for your post.

First, both "{0:C}" "{0:c}" will do the same since it's not case-sensitive.

The problem you encountered is described in a KB that is not published yet.
Here's some content of it:

KB919282
The value of a BoundField control is not formatted correctly when you set
the value of the DataFormatString member of the BoundField control in an
ASP.NET-connected Web application
SYMPTOMS

When you set the value of the DataFormatString member of a BoundField
control in an ASP.NET-connected Web application, the value of the
BoundField control is not formatted correctly. This problem occurs when the
following conditions are true:
* You are working with an ASP.NET-connencted Web application that is built
on the Microsoft .NET Framework 2.0.
* The application contains a DetailsView control or a GridView control
that in turn contains a BoundField control.
* The value of the HtmlEncode member of the BoundField control is set to
True in order to encode the value of the DataField member of the BoundField
control.
Note By default, the HtmlEncode member of a BoundField control is set to
True .

CAUSE

This problem occurs because the value in the DataField member of the
BoundField control is encoded before formatting is applied. When the value
of the DataField member is encoded, the data type of the value is changed
to String . Because the data type of the value of the DataField member is
changed, the value of the DataField member is not formatted correctly. For
example, if the value of the HtmlEncode member of the BoundField control is
set to True , the value of the BoundField control will be the same as the
result of the following pseudo-code:

String.Format( DataFormatString , HttpUtility.HtmlEncode( DataField ))

However, if the value of the HtmlEncode member of the BoundField control is
set to False , the value of the BoundField control will be the same as the
result of the following pseudo-code:

String.Format( DataFormatString , DataField )

RESOLUTION

To resolve this problem, set the value of the HtmlEncode member of the
BoundField control to False .

STATUS

This behavior is by design.

MORE INFORMATION

For more information about how to use the BoundField control, visit the
following Microsoft Developer Network (MSDN) Web site:
http://msdn2.microsoft.com/en-us/sys...ndfield_member
s.aspx

For more information about how to use the HtmlEncode member of the
BoundField control, visit the following MSDN Web site:
http://msdn2.microsoft.com/en-us/sys...ndfield.htmlen
code.aspx
Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 22 '06 #4
Excellent job, that's what I need it...

Victor

"Walter Wang [MSFT]" <wa****@online.microsoft.com> wrote in message
news:ML*************@TK2MSFTNGXA01.phx.gbl...
Hi Victor,

Thank you for your post.

First, both "{0:C}" "{0:c}" will do the same since it's not
case-sensitive.

The problem you encountered is described in a KB that is not published
yet.
Here's some content of it:

KB919282
The value of a BoundField control is not formatted correctly when you set
the value of the DataFormatString member of the BoundField control in an
ASP.NET-connected Web application
SYMPTOMS

When you set the value of the DataFormatString member of a BoundField
control in an ASP.NET-connected Web application, the value of the
BoundField control is not formatted correctly. This problem occurs when
the
following conditions are true:
* You are working with an ASP.NET-connencted Web application that is built
on the Microsoft .NET Framework 2.0.
* The application contains a DetailsView control or a GridView control
that in turn contains a BoundField control.
* The value of the HtmlEncode member of the BoundField control is set to
True in order to encode the value of the DataField member of the
BoundField
control.
Note By default, the HtmlEncode member of a BoundField control is set to
True .

CAUSE

This problem occurs because the value in the DataField member of the
BoundField control is encoded before formatting is applied. When the value
of the DataField member is encoded, the data type of the value is changed
to String . Because the data type of the value of the DataField member is
changed, the value of the DataField member is not formatted correctly. For
example, if the value of the HtmlEncode member of the BoundField control
is
set to True , the value of the BoundField control will be the same as the
result of the following pseudo-code:

String.Format( DataFormatString , HttpUtility.HtmlEncode( DataField ))

However, if the value of the HtmlEncode member of the BoundField control
is
set to False , the value of the BoundField control will be the same as the
result of the following pseudo-code:

String.Format( DataFormatString , DataField )

RESOLUTION

To resolve this problem, set the value of the HtmlEncode member of the
BoundField control to False .

STATUS

This behavior is by design.

MORE INFORMATION

For more information about how to use the BoundField control, visit the
following Microsoft Developer Network (MSDN) Web site:
http://msdn2.microsoft.com/en-us/sys...ndfield_member
s.aspx

For more information about how to use the HtmlEncode member of the
BoundField control, visit the following MSDN Web site:
http://msdn2.microsoft.com/en-us/sys...ndfield.htmlen
code.aspx
Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Jun 22 '06 #5
Hi Victor,

Appreciate your update and response. I am glad to hear that the problem has
been fixed. If you have any other questions or concerns, please do not
hesitate to contact us. It is always our pleasure to be of assistance.

Have a nice day!

Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 23 '06 #6
Try HtmlEncode="false"
Jul 5 '06 #7
Try HtmlEncode="false"
Jul 5 '06 #8
Try HtmlEncode="false"
Jul 5 '06 #9

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

Similar topics

3
by: washoetech | last post by:
I have a gridview control. In this grid view there is a column for the price of an item. Some of the prices have a dollar sign in front of it and some dont. How do I get rid of the dollar sign...
1
by: euan | last post by:
HI Guys, I have bee using conditional formatting in the datagrid recently and I am moving over to framework 2.0 and noticed the datagrid has been replaced by the gridview. So, I would like to do...
4
by: Nalaka | last post by:
Hi, I have two questions about gridViews. 1. How can I intercept the row/column values at loading to change values? 2. After I update a row (using default update functionality), how can I...
3
by: Simon Harvey | last post by:
Hi all, I'm having problems getting my date to format. Someone told me that with the GridView, you need to use a TemplateColumn and not a BoundColumn when displaying dates. Given that, can...
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...
3
by: CSharpguy | last post by:
I'm trying to format the GridView on my web form and its not working. for money I have {0:C} and for date fields, I have {0:d} and the format isn't changing, what else do I need to do to get the...
4
by: Ken Wigle | last post by:
All, I would be very grateful for any help on this question. I have an application in asp.net 2.0 where I dynamically create a datatable and then bind that to a gridview. Unfortunately, the...
2
by: Jacksm | last post by:
How can I align an asp:table columns with gridview columns (the widths)? I have tried setting table.column(0).width = gridview.column(0).width at page_load but it doesn't work. Thanks in advance
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...
2
by: tomh2099 | last post by:
Hi, Hi, I have an ASP.NET 2005 application (using VB) with a GridView control that needs to have the last 5 or 6 rows in Bold or maybe some other special formatting. Most of the rows show...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.