gridview - data format

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

I have a gridview control with a bound field as outlined below. The problem
is that the formatting is not happening. The data gets rendered as
12999.0000. It is being stored in a decimal data type. Any ideas?

<asp:boundfield headertext="Amount" datafield="amount"
dataformatstring="{0:C}"/>
TIA!
 
Hi Param,

Welcome.
As for the "DataFormatString" not work for the GridView BoundField problem,
it is caused by the new "HtmlEncode" setting of the GridView BoundField. By
default the GridView BoundField's "HtmlEncode" attribute is turn on so that
the databound value on that boundfields will be htmlencoded before rendered
out(for security consideration...) And in that case the DataFormatString
will not work. So in your scenario, you can just turn off the "htmlencode"
on that decimal databound field like:

<asp:BoundField HtmlEncode="false" DataField="UnitPrice"
DataFormatString="{0:C}" HeaderText="UnitPrice" SortExpression="UnitPrice"
/>

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)





--------------------
| From: <[email protected]>
| Subject: gridview - data format
| Date: Mon, 14 Nov 2005 15:09:33 -0600
| Lines: 13
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| Message-ID: <uM$M3#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: corp.lazardgroup.com 64.237.78.178
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:358065
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi all,
|
| I have a gridview control with a bound field as outlined below. The
problem
| is that the formatting is not happening. The data gets rendered as
| 12999.0000. It is being stored in a decimal data type. Any ideas?
|
| <asp:boundfield headertext="Amount" datafield="amount"
| dataformatstring="{0:C}"/>
| TIA!
|
|
|
|
|
 
Hi Param,

Does my suggestion in the last reply help you resolve this problem? If
there're anything else we can help, please feel free to post here. Thanks,


Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| X-Tomcat-ID: 150394533
| References: <uM$M3#[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: (e-mail address removed) (Steven Cheng[MSFT])
| Organization: Microsoft
| Date: Tue, 15 Nov 2005 08:20:17 GMT
| Subject: RE: gridview - data format
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Lines: 50
| Path: TK2MSFTNGXA02.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:358160
| NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182
|
| Hi Param,
|
| Welcome.
| As for the "DataFormatString" not work for the GridView BoundField
problem,
| it is caused by the new "HtmlEncode" setting of the GridView BoundField.
By
| default the GridView BoundField's "HtmlEncode" attribute is turn on so
that
| the databound value on that boundfields will be htmlencoded before
rendered
| out(for security consideration...) And in that case the DataFormatString
| will not work. So in your scenario, you can just turn off the
"htmlencode"
| on that decimal databound field like:
|
| <asp:BoundField HtmlEncode="false" DataField="UnitPrice"
| DataFormatString="{0:C}" HeaderText="UnitPrice"
SortExpression="UnitPrice"
| />
|
| Hope helps. Thanks,
|
| Steven Cheng
| Microsoft Online Support
|
| Get Secure! www.microsoft.com/security
| (This posting is provided "AS IS", with no warranties, and confers no
| rights.)
|
|
|
|
|
| --------------------
| | From: <[email protected]>
| | Subject: gridview - data format
| | Date: Mon, 14 Nov 2005 15:09:33 -0600
| | Lines: 13
| | X-Priority: 3
| | X-MSMail-Priority: Normal
| | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| | X-RFC2646: Format=Flowed; Original
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| | Message-ID: <uM$M3#[email protected]>
| | Newsgroups: microsoft.public.dotnet.framework.aspnet
| | NNTP-Posting-Host: corp.lazardgroup.com 64.237.78.178
| | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| | Xref: TK2MSFTNGXA02.phx.gbl
| microsoft.public.dotnet.framework.aspnet:358065
| | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| |
| | Hi all,
| |
| | I have a gridview control with a bound field as outlined below. The
| problem
| | is that the formatting is not happening. The data gets rendered as
| | 12999.0000. It is being stored in a decimal data type. Any ideas?
| |
| | <asp:boundfield headertext="Amount" datafield="amount"
| | dataformatstring="{0:C}"/>
| | TIA!
| |
| |
| |
| |
| |
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top