By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,474 Members | 1,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,474 IT Pros & Developers. It's quick & easy.

Gridview decimal point is a comma?

P: n/a
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

Jan 20 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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

Jan 20 '06 #2

P: n/a
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

Jan 20 '06 #3

P: n/a
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

Jan 20 '06 #4

P: n/a
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 :-)

Jan 20 '06 #5

P: n/a
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 :-)

Jan 20 '06 #6

P: n/a
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

Jan 20 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.