Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dataformatstring not working

Status
Not open for further replies.

jrl237

IS-IT--Management
Jan 29, 2002
61
US
Can anyone see why the following code isn't working? I'm trying to format a phone number in a datagrid like (201) 555-1234 but all I get is 2015551234.

<ASP:DATAGRID ID=&quot;dgTest&quot; RUNAT=&quot;server&quot; AUTOGENERATECOLUMNS=&quot;False&quot;>
<COLUMNS>
<ASP:BOUNDCOLUMN DATAFIELD=&quot;Phone&quot; HEADERTEXT=&quot;Phone&quot; DATAFORMATSTRING=&quot;{0:(###) ###-####}&quot; />
</COLUMNS>
</ASP:DATAGRID>

I've had this problem before when the datafield wasn't a string. Changing the field type to VarChar(10) has solved the problem in the past, but that isn't an option on this one.

The phone field is actually a couple of Integer columns, which I'm trying to convert in the select statement like this:

SELECT Cast((Convert(Char(6),ANI) + Convert(Char(4),Exchange)) AS Char(10)) AS Phone

I can actually make it work if I do all of the formatting in the select statement and just leave out the dataformatstring in the datagrid, but shouldn't the datagrid be able to do the formatting?

Is there a better way to do this? Anyone know why it doesn't work as advertised?

Any help would be appreciated.

JRL
 
From what I can see you are trying to use the DataFormatString to format a number type.
DataFormatString only works on .... yes that's right strings That'l do donkey, that'l do
[bravo] Mark
 
Actually, that's not true. Dataformatstring works on date and time types, currency types, numbers, etc. In fact, it seems, it works on everything but strings. That was my problem. I changed the select to this:

SELECT Cast((Convert(Char(6),Calls.ANI) + Convert(Char(4),Exchange)) AS BigInt) AS Phone

which converts Phone to be a Big Integer, and all is well.

It's called dataformatstring because it's a string.

Thanks anyway.
 
umm ic.
Didn't mean to be sarcastic, just messing around.

Glad you got it to work though. That'l do donkey, that'l do
[bravo] Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top