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

[Solved] Formatting Column Data

13 Answers 601 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 11 Apr 2008, 04:26 PM
I have a RadGrid that I am trying to use to build a shopping cart. I am having a hard time with formatting the column that will hold the items cost.

This is what I have for that column:

<telerik:GridBoundColumn   
   DataField="Price"   
   HeaderText="Price" 
   DataFormatString="${0:###,###.##}"   
   FooterText="Sub-Total: $" 
   Aggregate="sum">   
</telerik:GridBoundColumn> 

The problem I am having is this: If the item cost is $50.00 it only display's $51. Is it possible to have it display the .00? If I set the DataFormatString to "${0}" I get $51.0000. How can I control the amount of decimal places? The data is being pulled from a SQL table and that column data type is MONEY.

Also I would like to display the sub-total of all my items. It formats the sum as $123.0000 as well. How do I control the amount of decimals here? The footer format doesn't seem to be controlled by the DataFormatString.

I'm sure RadGrid has been used many times for this purpose so I suspect there is an easy solution?

Thanks!

Paul

13 Answers, 1 is accepted

Sort by
0
Paul
Top achievements
Rank 1
answered on 11 Apr 2008, 07:53 PM
I resolved this myself.

I set DataFormatString="${0}".

I also had to change my SQL Data Type to decimal vs money. Once I changed it to decimal and specified in the database that I wanted only 2 numbers after the decimal my column formatted just like I wanted it to.

I still would like to know if the same results can be achieve somehow using the money data type. Fortunately I don't need the extra precision that data type offers for handling money, but someday I may.
0
Paul
Top achievements
Rank 1
answered on 15 Apr 2008, 07:33 PM
I now have an actual need for formatting the SQL Money datatype in my RadGrid. Unfortunately it seems the RadGrid is not equiped well to format this type (or at least modify the way it is displayed). The money data type returns something like 123456.1234 and I need to reformat to $123,456.12 however the following happens: If I set DataFormatString=

"${0:###,###.##}" then the column data displays correctly (unless the cents amount is has a trailing zero, in which case the 0 is not displayed.. I.E. $1.10 displays as $1.1. If I set DataFormatString="${0}" I get $123456.1234. The footer Aggregate="Sum" always returns 123456.1234 and there does not appear to be a way to reformat this value.

Is there something I am missing that would fix what I need above, if not it would be nice if the production release will fix the display of the DataFormatString not showing the trailing zero as well as apply to the footer format (or make a way for the footer to have its own data format string).

0
Accepted
Iana Tsolova
Telerik team
answered on 16 Apr 2008, 08:19 AM
Hello Paul,

You don't need to change your data type from money to decimal to achieve your goal. If you want to display two signs after the decimal point you need to use DataFormatString="${0:###,###.00}".

Concerning the aggregated value in the footer, unfortunately we don't support formatting for it yet but you may be happy to know that it will be supported for the official Q1 2008 release (through the FooterAggregateFormatString property of the column.

Best wishes,
Iana
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Josh Winkler
Top achievements
Rank 1
answered on 16 Apr 2008, 02:13 PM
I am trying this but it will now format. The field is a varchar(50). Simply trying to format the phone number but it doesnt format anything. Please let me know. Thanks.

<

radG:GridBoundColumn DataField="WorkPhone" HeaderText="Work Phone" DataFormatString="{0:###-###-####}" />

0
Paul
Top achievements
Rank 1
answered on 16 Apr 2008, 02:21 PM
Thanks! That did the trick.. Can't wait for it to be released. Hopefully we woun't have much longer to wait ;)

Paul
0
Paul
Top achievements
Rank 1
answered on 16 Apr 2008, 02:22 PM
Josh,

Try this instead:

DataFormatString="{0:(###)###-####}"

This is how it appears on the demo sites example.

Paul
0
Sebastian
Telerik team
answered on 16 Apr 2008, 02:23 PM
Hello Paul,

The Q1 2008 release of RadControls Prometheus will be announced by the end of the day. I hope this is good news for you.

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Paul
Top achievements
Rank 1
answered on 16 Apr 2008, 02:29 PM
Excellent :)
0
Josh Winkler
Top achievements
Rank 1
answered on 16 Apr 2008, 02:33 PM

Thanks for the response Paul. Yeah I already tried that one also. I tried multiple different formats it just wont work. Thanks again for the response though.

Here is the full code of the grid if that helps...

<

radG:RadGrid runat="server" ID="ParentContactList" SkinID="GridSkin" CssClass="radGrids">

<MasterTableView>

<CommandItemSettings AddNewRecordText="Add New Parent Contact" />

<Columns>

<radG:GridEditCommandColumn ButtonType="ImageButton" UpdateImageUrl="..\..\Images\Misc\Update.gif"

EditImageUrl="..\..\Images\Misc\Edit.gif" InsertImageUrl="..\..\Images\Misc\Update.gif" CancelImageUrl="..\..\Images\Misc\Cancel.gif"

UniqueName="EditCommandColumn" ItemStyle-Width="20"/>

<radG:GridDropDownColumn HeaderText="Contact Type" DataField="ContactTypeID" UniqueName="ContactType" Visible="False" ListTextField="ContactTypeDesc" ListValueField="ContactTypeID" />

<radG:GridDropDownColumn HeaderText="Title" DataField="Title" UniqueName="ContactTitle" Visible="False" ListTextField="Title" ListValueField="TitleID" />

<radG:GridDropDownColumn HeaderText="Prefix" DataField="PrefixName" ListTextField="LookupText" ListValueField="LookupID" UniqueName="ParentPrefixName" Visible="false" />

<radG:GridBoundColumn UniqueName="ContactID" DataField="ContactID" Visible="False" ReadOnly="true" />

<radG:GridBoundColumn UniqueName="FirstName" DataField="FirstName" HeaderText="First Name"/>

<radG:GridBoundColumn UniqueName="MiddleName" DataField="MiddleName" HeaderText="Middle Name" Visible="false"/>

<radG:GridBoundColumn UniqueName="LastName" DataField="LastName" HeaderText="Last Name"/>

<radG:GridBoundColumn UniqueName="Email" DataField="Email" HeaderText="Email" EditFormColumnIndex="1" />

<radG:GridBoundColumn DataField="WorkPhone" HeaderText="Work Phone" DataFormatString="{0:(###) ###-####}" />

<radG:GridTemplateColumn UniqueName="WorkPhone" DataField="WorkPhone" EditFormColumnIndex="1" Visible="false" >

<EditItemTemplate>

<rad:RadMaskedTextBox ID="WorkPhoneBox" runat="server" Mask="###-###-####" DisplayMask="###-###-####" DisplayPromptChar="_" Text='<%# Bind("WorkPhone") %>'>

</rad:RadMaskedTextBox>

</EditItemTemplate>

</radG:GridTemplateColumn>

<radG:GridBoundColumn UniqueName="Extension" DataField="Extension" HeaderText="Extension" EditFormColumnIndex="1" />

<radG:GridTemplateColumn UniqueName="FaxNumber" HeaderText="Fax" EditFormColumnIndex="1" Visible="False" >

<EditItemTemplate>

<rad:RadMaskedTextBox ID="FaxBox" runat="server" Mask="###-###-####" DisplayMask="###-###-####" DisplayPromptChar="_" Text='<%# Bind("FaxNumber") %>'>

</rad:RadMaskedTextBox>

</EditItemTemplate>

</radG:GridTemplateColumn>

<radG:GridTemplateColumn UniqueName="CellPhone" HeaderText="Cell" EditFormColumnIndex="1" Visible="False" >

<EditItemTemplate>

<rad:RadMaskedTextBox ID="CellBox" runat="server" Mask="###-###-####" DisplayMask="###-###-####" DisplayPromptChar="_" Text='<%# Bind("CellPhone") %>'>

</rad:RadMaskedTextBox>

</EditItemTemplate>

</radG:GridTemplateColumn>

<radG:GridTemplateColumn HeaderText="Visit Date" UniqueName="VisitDate" Visible="False">

<EditItemTemplate>

<input runat="server" type="text" id="ParentVisitDate" onclick="displayDatePicker('ParentVisitDate');" class="TextboxDate" onkeydown="noKeysExceptTab(event);"/>

</EditItemTemplate>

</radG:GridTemplateColumn>

<radG:GridTemplateColumn HeaderText="Letter Date" UniqueName="LetterDate" Visible="False">

<EditItemTemplate>

<input runat="server" type="text" id="ParentLetterDate" onclick="displayDatePicker('ParentLetterDate');" class="TextboxDate" onkeydown="noKeysExceptTab(event);"/>

</EditItemTemplate>

</radG:GridTemplateColumn>

<radG:GridTemplateColumn HeaderText="Next Contact Date" UniqueName="NextContactDate" Visible="False">

<EditItemTemplate>

<input runat="server" type="text" id="ParentContactDate" onclick="displayDatePicker('ParentContactDate');" class="TextboxDate" onkeydown="noKeysExceptTab(event);"/>

</EditItemTemplate>

</radG:GridTemplateColumn>

<radG:GridBoundColumn HeaderText="Referred By" UniqueName="ReferredBy" DataField="ReferredBy" Visible="False" />

<radG:GridBoundColumn HeaderText="Contact Notes" UniqueName="Notes" DataField="Notes" Visible="False" EditFormColumnIndex="1" />

<radG:GridCheckBoxColumn UniqueName="Active" DataField="Status" HeaderText="Active?" ItemStyle-Width="20"/>

</Columns>

<EditFormSettings ColumnNumber="2">

<EditColumn ButtonType="ImageButton" UpdateImageUrl="..\..\Images\Misc\Save.gif" EditImageUrl="..\..\Images\Misc\Edit.gif"

InsertImageUrl="..\..\Images\Misc\Save.gif" CancelImageUrl="..\..\Images\Misc\Cancel.gif" InsertText="Insert Order"

UpdateText="Update record" UniqueName="ParentEditCommandColumn1" CancelText="Cancel edit"/>

</EditFormSettings>

<NoRecordsTemplate>Currently There Are No Contacts For This Parent Company</NoRecordsTemplate>

</MasterTableView>

</radG:RadGrid>

0
Paul
Top achievements
Rank 1
answered on 16 Apr 2008, 02:39 PM
Josh,

Are you using Prometheus or an earlier version of the RadGrid? Not sure if it makes a difference or not but it helps to know which version you are using.
0
Josh Winkler
Top achievements
Rank 1
answered on 16 Apr 2008, 02:46 PM
Its the standard RadGrid and we are using the RadGrid.Net2.dll version. If thats what you were asking. Sorry Im a "newbie" to the Rad Controls but so far they are great tools! Thanks again for your prompt reply Paul.
0
Paul
Top achievements
Rank 1
answered on 16 Apr 2008, 02:47 PM
Josh,

It may also have to do with the fact your phone number is stored as a varchar(50) and not and int for instance. If you store the phone number as a integer (I.E. 5551234567) then your formatting should work. But given its a string, it may not know how to handle the numbers (and you could simply store the number in your database as (555)123-4567 and not bother with having to format it elsewhere).

It's probably best to strore in your DB as an int and convert it to string later on in your code for display purposes (if needed) and let the RadGrid do the formatting if it's displayed in a grid.

Paul
0
Josh Winkler
Top achievements
Rank 1
answered on 16 Apr 2008, 02:56 PM
Ok great, thats what I was curious about. We are doing this project for another company and we are not able to change the data structure so my hands are tied there. But now knowing that with the grid I can just format it in the code behind for display on the page. Just looking for a simple shortcut. :) Thanks so much for your replies sir and have a great day.
Tags
Grid
Asked by
Paul
Top achievements
Rank 1
Answers by
Paul
Top achievements
Rank 1
Iana Tsolova
Telerik team
Josh Winkler
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or