This is a migrated thread and some comments may be shown as answers.

DataFormatingString for a GridCalculatedColumn

16 Answers 188 Views
Grid
This is a migrated thread and some comments may be shown as answers.
fecteaum
Top achievements
Rank 1
fecteaum asked on 11 Sep 2008, 01:11 PM
Hi,

I am trying to add a DataFormatString to a GridCalculatedColumn in my Grid. I have a column Quantity
<telerik:GridNumericColumn SortExpression="Quantity" 
                    DataType="System.Decimal" HeaderText="Quantity" 
                    DataField="Quantity" UniqueName="Quantity" 
                    DataFormatString="{0:F3}" Visible="true">
             <ItemStyle HorizontalAlign="Right" />
</telerik:GridNumericColumn>

a column Unit_Price
<telerik:GridNumericColumn SortExpression="Unit_price" 
                     DataType="System.Decimal" HeaderText="Unit price"
                     DataField="Unit_price" UniqueName="Unit_price"
                     DataFormatString="{0:C}" Visible="true">
    <ItemStyle HorizontalAlign="Right" />
</telerik:GridNumericColumn>

and a column Total
<telerik:GridCalculatedColumn HeaderText="Total" UniqueName="Total" 
                     DataType="System.Double"
                     DataFields="Quantity, Unit_price" Expression="{0}*{1}"
                     DataFormatString="{0:C}">
    <ItemStyle HorizontalAlign="Right" Width="80px"></ItemStyle>
</telerik:GridCalculatedColumn>

When i run the project i have the following result::
Item    Quantity      Unit price                   total
1            7.000          17.95 $  125,65000000
2          11.000            5.00 $    55.00000000

Is it possible to have this instead:
Item     Quantity      Unit price            Total
1             7.000          17.95 $      125,65 $
2            11.000           5.00 $        55.00 $

Thanks

16 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 11 Sep 2008, 05:22 PM
Hello Matthieu,

I notice you already implemented a similar code in the first column:
DataFormatString="{0:F3}" 

The same approach could be used to achieve the desired currency format:
DataFormatString="{0:C2}" 

More information concerning this subject can be found here:
BoundField.DataFormatString Property

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
fecteaum
Top achievements
Rank 1
answered on 11 Sep 2008, 05:37 PM
Hi,

I tried it, but it does not work.  I don't know if it's because it's a GridCalculatedColumn.

I am using the DatatFormatString="{0:C}" for the column Unite_price and i didn't put a 2 after the C to have 2 digits and a $.

Thanks
0
Daniel
Telerik team
answered on 11 Sep 2008, 05:53 PM
Hello Matthieu,

I attached a simple example illustrating the needed approach:

Please note that:
{0:C} is default (it depends on your regional settings)
{0:C3} is custom - we specified a fixed-point currency value with three decimal places

All the best,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
fecteaum
Top achievements
Rank 1
answered on 11 Sep 2008, 08:14 PM
Hello,

I don't know why, it's still not working even if i put the DataFormatString="{0:C2}".

I don't know if it's is because it's in a detail grid but i still have the same mistake.

Item    Quantity    Unite price                   Total
1            7.000         17.95 $    125.65000000
2           11.000          5.00 $      55.00000000
0
Daniel
Telerik team
answered on 12 Sep 2008, 05:47 AM
Hello Matthieu,

Could you please send us a simple working project illustrating the mentioned behavior via regular support ticket?
Thus we can examine your code locally and then give you the appropriate answer.

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Myriam
Top achievements
Rank 1
answered on 19 Sep 2008, 05:36 PM
Hello Telerik
I have the same issue. But I have the decimals correct.
I just don't have the $ sign to my "sous total" column but I can see it with my "prix" column.
Here are my columns.

<telerik:GridNumericColumn SortExpression="QUANTITE"

DataType="System.Decimal" HeaderText="QUANTITE"

DataField="QUANTITE" UniqueName="QUANTITE"

DataFormatString="{0:N0}" Visible="true">

<ItemStyle HorizontalAlign="Right" />

</telerik:GridNumericColumn>

<telerik:GridNumericColumn SortExpression="PRIX"

DataType="System.decimal" HeaderText="PRIX"

DataField="PRIX" UniqueName="PRIX"

DataFormatString="{0:C}" Visible="true">

<ItemStyle HorizontalAlign="Right" />

</telerik:GridNumericColumn>

<telerik:GridCalculatedColumn HeaderText="Sous Total" UniqueName="SousTotal"

DataType="System.decimal"

DataFields="QUANTITE, PRIX" Expression="{1}*{0}"

DataFormatString="{0:C2}">

<ItemStyle HorizontalAlign="Right" Width="80px"></ItemStyle>

</telerik:GridCalculatedColumn>



0
Daniel
Telerik team
answered on 22 Sep 2008, 04:27 PM
Hello Myriam and Matthieu,

Please try HtmlEncode="false" setting for your columns.

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Myriam
Top achievements
Rank 1
answered on 22 Sep 2008, 05:05 PM
Thanks Telerik for your answer.
But unfortunetly it doesn't work as I got the error message:
"Le type 'Telerik.Web.UI.GridCalculatedColumn' ne possède pas de propriété publique appelée 'HtmlEncode'."
Which mean that GridCalculatedColumn doesn't have a property called HtmlEncode.
Any other ideas?
0
Daniel
Telerik team
answered on 25 Sep 2008, 12:36 PM
Hello Myriam,

Excuse me but I accidentaly forgot to mention that the referenced feature will be implemented for the next Service Pack release which is expected at the end of this month.

In the meantime you can test the latest unofficial build attached to the thread.

Best regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Myriam
Top achievements
Rank 1
answered on 25 Sep 2008, 01:04 PM
Hello Daniel
I took a look at what you sent me.
Sorry but would you like that I install that instead my telerik or it's just to see if it's gonna work for me when your gonna make available the next service pack?
About this service pack, it will be available at the end of september right?
Thanks a lot
0
Daniel
Telerik team
answered on 25 Sep 2008, 04:35 PM
Hello Myriam,

Thank you for the interest in RadControls for ASP.NET AJAX.

The features and fixes available in the unofficial build will be part of the upcoming service pack.

As I mentioned before it is expected until the end of the September. Check our website frequently in order to keep yourself informed.

Best regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Myriam
Top achievements
Rank 1
answered on 29 Sep 2008, 08:27 PM
Thanks for your reply
I would like to know how to install it in my project to make this work
Thanks in advance
0
Sebastian
Telerik team
answered on 30 Sep 2008, 07:31 AM
Hi Myriam,

How to update our controls to another version or license you can learn from the following knowledge base article on our site:

http://www.telerik.com/support/kb/article/b454K-kad-b454T-a-b454c-a.aspx

Best regards,
Stephen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Myriam
Top achievements
Rank 1
answered on 30 Sep 2008, 01:13 PM
Hello Stephen
Thanks for the answer.
I tried it but I get the error "TPSResult is not a column that exist" or something like that.
How can I know which version of telerik I am using in my project (just to know if I'm ok)
Thank you
0
Jeremy
Top achievements
Rank 1
answered on 31 Mar 2009, 08:02 PM
I know this post is old but have you tried to change:
<telerik:GridCalculatedColumn HeaderText="Total" UniqueName="Total" 
                     DataType="System.Double"
                     DataFields="Quantity, Unit_price" Expression="{0}*{1}"
                     DataFormatString="{0:C}">
    <ItemStyle HorizontalAlign="Right" Width="80px"></ItemStyle>
</telerik:GridCalculatedColumn>

to:

<telerik:GridCalculatedColumn HeaderText="Total" UniqueName="Total" 
                     DataType="System.Decimal"
                     DataFields="Quantity, Unit_price" Expression="{0}*{1}"
                     DataFormatString="{0:C}">
    <ItemStyle HorizontalAlign="Right" Width="80px"></ItemStyle>
</telerik:GridCalculatedColumn>
0
Myriam
Top achievements
Rank 1
answered on 31 Mar 2009, 08:07 PM
Hello Jeremy
Thank you for your reply
That's what I've done and this is working. Sorry that I didn't come to tell the answer before.
Tags
Grid
Asked by
fecteaum
Top achievements
Rank 1
Answers by
Daniel
Telerik team
fecteaum
Top achievements
Rank 1
Myriam
Top achievements
Rank 1
Sebastian
Telerik team
Jeremy
Top achievements
Rank 1
Share this question
or