Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Gridview decimal point is a comma?

Reply
Thread Tools

Gridview decimal point is a comma?

 
 
ibiza
Guest
Posts: n/a
 
      01-20-2006
Hi all,

I've binded some data from a DB in a gridview and one of the values is
a float. Even if the flot is represented as 4.2 in the DB, it is
rendered as 4,2 in the gridview, with a comma. When I edit the row, it
is still a comma in the editable textbox. And if I click on Update that
way, it gives an error, that the input value cannot be converted to a
float, when doing the UPDATE. If I change the comma for a point, it
works, which I want.

Here is my question : How can I ensure that the data displayed in the
gridview, editable or not, renders with a point and not a comma?

I've been googling a lot without finding an answer yet...

Thank you very much!

ibiza

 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
Guest
Posts: n/a
 
      01-20-2006
You can format a BoundField on the GridView using the DataFormatString and
set the HtmlEncode property to false

http://msdn2.microsoft.com/en-us/lib...matstring.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"ibiza" wrote:

> Hi all,
>
> I've binded some data from a DB in a gridview and one of the values is
> a float. Even if the flot is represented as 4.2 in the DB, it is
> rendered as 4,2 in the gridview, with a comma. When I edit the row, it
> is still a comma in the editable textbox. And if I click on Update that
> way, it gives an error, that the input value cannot be converted to a
> float, when doing the UPDATE. If I change the comma for a point, it
> works, which I want.
>
> Here is my question : How can I ensure that the data displayed in the
> gridview, editable or not, renders with a point and not a comma?
>
> I've been googling a lot without finding an answer yet...
>
> Thank you very much!
>
> ibiza
>
>

 
Reply With Quote
 
 
 
 
ibiza
Guest
Posts: n/a
 
      01-20-2006
Thanks for the quick answer!

On MSDN, they use the DataFormatString like this :

<asp:boundfield datafield="discount"
dataformatstring="{0:F4}%"
itemstyle-horizontalalign="Right"
headertext="Discount"/>

How can I use it with a TemplateField? There is no DataFormatString
property for it...is it?

And why should the HtmlEncode property be set to false? I don't
understand that one

Thanks again for your help!

ibiza

 
Reply With Quote
 
=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
Guest
Posts: n/a
 
      01-20-2006
To bind the data to controls within a templatefield you would use either
DataBinder.Eval or the 2-way databinding syntax of Bind. Both accept a
formatting string expression, e.g.

<asp:TemplateField HeaderText="discount">
<EditItemTemplate>
<asp:TextBox ID="txtNumber" runat="server" Text='<%# Bind("discount",
"{0:F4}") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("discount",
"{0:F4}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

The reason for using HTMLEncode=false on the BoundField was explained on the
article whose link I gave you as follows:

"When the HtmlEncode property is true, the value of the field is HTML
encoded to its string representation before the formatting string is applied.
For some objects, such as dates, you might want to control how the object is
displayed with a formatting string. In those cases, you must set the
HtmlEncode property to false."

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"ibiza" wrote:

> Thanks for the quick answer!
>
> On MSDN, they use the DataFormatString like this :
>
> <asp:boundfield datafield="discount"
> dataformatstring="{0:F4}%"
> itemstyle-horizontalalign="Right"
> headertext="Discount"/>
>
> How can I use it with a TemplateField? There is no DataFormatString
> property for it...is it?
>
> And why should the HtmlEncode property be set to false? I don't
> understand that one
>
> Thanks again for your help!
>
> ibiza
>
>

 
Reply With Quote
 
ibiza
Guest
Posts: n/a
 
      01-20-2006
Okay, you're really helping me!

as DataFormatString, I think a TemplateField does not have the
HtmlEncode property...is there a workaround?

One last question : what here will change the comma to a point? For
example, Eval("discount", "{0:F4}") will format the field, but not
change the point to a comma, am I correct?

thanks again

 
Reply With Quote
 
=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
Guest
Posts: n/a
 
      01-20-2006
The standard format expressions are dependent on the Page.Culture setting or
the global culture setting on your server. You might examine a bit further
the cultureinfo object:
http://msdn2.microsoft.com/en-us/lib...ltureinfo.aspx

You can however manipulate the format to any thing you want as explained in
detail in this section of articles:
http://msdn2.microsoft.com/en-us/library/26etazsy.aspx

For example you can type Eval("discount", "{0:#0,00}") to get at least one
number followed by a comma then 2 decimals.

As for the DataFormatString for TemplateField the HtmlEncode issue does not
apply.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"ibiza" wrote:

> Okay, you're really helping me!
>
> as DataFormatString, I think a TemplateField does not have the
> HtmlEncode property...is there a workaround?
>
> One last question : what here will change the comma to a point? For
> example, Eval("discount", "{0:F4}") will format the field, but not
> change the point to a comma, am I correct?
>
> thanks again
>
>

 
Reply With Quote
 
ibiza
Guest
Posts: n/a
 
      01-20-2006
Thank you very much for the Culture information.

I finally solved the issue with adding a <globalization culture="en-US"
/> directive in <system.web> from web.config. That way, I have no
formatting to do and it will work through my entire webapp.

Thanks again!

Bruno

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Share-Point-2010 ,Share-Point -2010 Training , Share-point-2010Hyderabad , Share-point-2010 Institute Saraswati lakki ASP .Net 0 01-06-2012 06:39 AM
TypeError: unsupported operand type(s) for -: 'Decimal' and 'Decimal'. Why? Gilbert Fine Python 8 08-01-2007 01:58 AM
How to change decimal point ',' to decimal comma ',' PERO Perl Misc 4 04-13-2007 05:22 PM
Decimal to Packed Decimal Conversion in C++ Ven C++ 3 08-01-2006 03:56 PM
Scenario 5: IS-IS routing on Frame Relay Multi-point and Point-to-Point David Sudjiman Cisco 0 06-08-2006 09:11 AM



Advertisments