For the Web Grid I am trying to Apply formatting to One of the Grid Column for Phone formatting usinf the code behind.
I am using it at a control level.
igGrid.Columns.FromKey("phone").Format = "(###) ###-####";
It doesn't seems to be working.
The phone no is a 10 digit number.
It displays number 1234567890 and i want (123) 456-7890
Please advice further .
Darrell Kress"]Wait, this is a WinGrid question,
Did this ever get resolved. The original post says "Web". If we're talking about WinGrids only, could you please move this thread to that forum.
I'm following this one because I expect to have a similar issue.
What is the DataType of the Data? What is the DataType of the UltraGridColumn?
The DataType of the data would need to be a numeric, not string type.
I tried using
but still it is not formatting.
Please advice
Wait, this is a WinGrid question, you can't access the columns collection in the WebGrid via a string accessor.
I tried this out with .... well lets just post the code
In page load
DataTable dt = new DataTable(); dt.Columns.Add("blah", typeof(DateTime)); dt.Columns.Add("phoneAsNumber", typeof(decimal)); dt.Columns.Add("phoneAsString", typeof(string)); dt.Rows.Add(new object[ { new DateTime(2008, 3, 31, 17, 30, 0), 8002318588, "8002318588" }); dt.Rows.Add(new object[ { new DateTime(2008, 3, 31, 17, 45, 0) }); this.UltraWebGrid1.DataSource = dt; this.UltraWebGrid1.DataBind();
in InitializeLayout
e.Layout.Bands[0].Columns.FromKey("blah").Format = "HH:mm"; e.Layout.Bands[0].Columns.FromKey("phoneAsNumber").Format = "(###)###-####"; e.Layout.Bands[0].Columns.FromKey("phoneAsString").Format = "(###)###-####";
The result was that the phoneAsNumber was formatted correctly, as ( 800 ) 231 - 8588 ( extra white space added by me for easy visualization).
The phoneAsString did not format, as expected. The Format string provided is passed to the .ToString() method off the object being shown. The System.String class does not except a format string to format it's data.