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
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:###,###.##}" 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).
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
<
radG:GridBoundColumn DataField="WorkPhone" HeaderText="Work Phone" DataFormatString="{0:###-###-####}" />
Paul
Try this instead:
DataFormatString="{0:(###)###-####}"
This is how it appears on the demo sites example.
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
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>
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.
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