Having trouble getting a radgrid column to format as $1,234.00; it always displays as 1234. The database field is Double. The code is as follows:
Any hints as to what I'm missing would be appreciated.
-Scott
<telerik:RadGrid ID="RadGrid1" runat="server" style="margin-top:25px;"AutoGenerateColumns="true" oncolumncreated="RadGrid1_ColumnCreated"> <MasterTableView TableLayout="Fixed" /> <ClientSettings EnableRowHoverStyle="true" > <Selecting AllowRowSelect="False"/> <ClientEvents /> <Scrolling AllowScroll="True"/> <Resizing AllowColumnResize="true" AllowResizeToFit="true" ResizeGridOnColumnResize="true" /> </ClientSettings> </telerik:RadGrid>using System;using System.Collections.Generic;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Telerik.Web.UI;using System.Data;using myNameSpace.BusinessLogic.myLogic;namespace myNameSpace{ public partial class myScreen : System.Web.UI.UserControl { private MyController myController = new MyController(); protected void Page_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); List<Guid> thisPositionIds = myController.GetPositionIDs(); // add 1st column, the Item dt.Columns.Add("Item"); // make the Annual Costs columns foreach (Guid positionId in thisPositionIds) { // add a column dt.Columns.Add(new DataColumn(myController.GetPositionName(positionId) + System.Environment.NewLine + "Annual Costs", System.Type.GetType("System.Decimal"))); } // get the data for the rows List<Guid> thisItemIds = myController.GetItemIDs(); foreach (Guid itemID in thisItemIds) { DataRow dr = dt.NewRow(); // enter the first column, the Item Name dr["Item"] = myController.GetItemName(itemID); // enter the final set of columns, the Annual Costs foreach (Guid positionId in thisPositionIds) { dr[myController.GetPositionName(positionId) + System.Environment.NewLine + "Annual Costs"] = myController.GetAnnualCosts(itemID, positionId); } dt.Rows.Add(dr); } RadGrid1.DataSource = dt; RadGrid1.DataBind(); } protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e) { if (e.Column.ColumnType == "GridBoundColumn") { // get column header text string colName = e.Column.UniqueName; // get last 12 chars of text (if it is long enough) string colNameEnd; if (colName.Length >= 12) colNameEnd = colName.Substring(colName.Length - 12, 12); else colNameEnd = "x"; // format according to which column this if (colName == "Item") e.Column.HeaderStyle.Width = Unit.Pixel(80); else if (colNameEnd == "Annual Costs") { (e.Column as GridBoundColumn).DataFormatString = "{0:C}"; } } } }}Any hints as to what I'm missing would be appreciated.
-Scott