number format

  • Thread starter Thread starter JFB
  • Start date Start date
J

JFB

Hi all,
How can I format a fax number as 888-333-444?
The number is coming from database as 8883334444
<ItemTemplate>
<%#container.dataItem("cfax")%>
</ItemTemplate>

Tks

JFB
 
Hi JFB,

I'm sure there is a better method, and using DataBinder.Eval you should be
able to format the number using something like

[C#]
<%# DataBinder.Eval(Container.DataItem, "cfax", "{0:###-###-####}") %>

However, I was unable to properly format the number that way so an
alternative method is to call a method that formats the number.

[C#]
<%# Format(DataBinder.Eval(Container.DataItem, "fax")) %>

Where Format is defined as


public string Format(object value)
{
long n = Convert.ToInt64(value);
return n.ToString("###-###-####");
}
 
Tks for you reply Morten,
<%# DataBinder.Eval(Container.DataItem, "cfax", "{0:###-###-####}") %>
I try the above code but it's not showing the format in my datagrid and I
don't get any errors...
Any ideas??
Rgds

JFB




Hi JFB,

I'm sure there is a better method, and using DataBinder.Eval you should be
able to format the number using something like

[C#]
<%# DataBinder.Eval(Container.DataItem, "cfax", "{0:###-###-####}") %>

However, I was unable to properly format the number that way so an
alternative method is to call a method that formats the number.

[C#]
<%# Format(DataBinder.Eval(Container.DataItem, "fax")) %>

Where Format is defined as


public string Format(object value)
{
long n = Convert.ToInt64(value);
return n.ToString("###-###-####");
}
 
Maybe because phone field is coming as varchar??
Any ideas
tks

JFB

JFB said:
Tks for you reply Morten,
<%# DataBinder.Eval(Container.DataItem, "cfax", "{0:###-###-####}") %>
I try the above code but it's not showing the format in my datagrid and I
don't get any errors...
Any ideas??
Rgds

JFB




Hi JFB,

I'm sure there is a better method, and using DataBinder.Eval you should be
able to format the number using something like

[C#]
<%# DataBinder.Eval(Container.DataItem, "cfax", "{0:###-###-####}") %>

However, I was unable to properly format the number that way so an
alternative method is to call a method that formats the number.

[C#]
<%# Format(DataBinder.Eval(Container.DataItem, "fax")) %>

Where Format is defined as


public string Format(object value)
{
long n = Convert.ToInt64(value);
return n.ToString("###-###-####");
}





Hi all,
How can I format a fax number as 888-333-444?
The number is coming from database as 8883334444
<ItemTemplate>
<%#container.dataItem("cfax")%>
</ItemTemplate>

Tks

JFB
 
I couldn't get it to work either, and it may be because it is not
identified as a number, but the other method should work.


Maybe because phone field is coming as varchar??
Any ideas
tks

JFB

JFB said:
Tks for you reply Morten,
<%# DataBinder.Eval(Container.DataItem, "cfax", "{0:###-###-####}") %>
I try the above code but it's not showing the format in my datagrid and
I
don't get any errors...
Any ideas??
Rgds

JFB




Hi JFB,

I'm sure there is a better method, and using DataBinder.Eval you should
be
able to format the number using something like

[C#]
<%# DataBinder.Eval(Container.DataItem, "cfax", "{0:###-###-####}") %>

However, I was unable to properly format the number that way so an
alternative method is to call a method that formats the number.

[C#]
<%# Format(DataBinder.Eval(Container.DataItem, "fax")) %>

Where Format is defined as


public string Format(object value)
{
long n = Convert.ToInt64(value);
return n.ToString("###-###-####");
}





Hi all,
How can I format a fax number as 888-333-444?
The number is coming from database as 8883334444
<ItemTemplate>
<%#container.dataItem("cfax")%>
</ItemTemplate>

Tks

JFB
 
Tks for reply Morten,
Either way I couldn't made it to work.
I'm using vb.net function

Function Format(ByVal value As Object)

Dim n As Long = Convert.ToInt64(value)

Return n.ToString("###-###-####")

End Function

ERROR: System.FormatException: Input string was not in a correct format. at
System.Number.ParseInt64(String s, NumberStyles style, NumberFormatInfo
info) at System.String.System.IConvertible.ToInt64(IFormatProvider provider)
at System.Convert.ToInt64(Object value)

Any Ideas??
Tks

JFB


I couldn't get it to work either, and it may be because it is not
identified as a number, but the other method should work.


Maybe because phone field is coming as varchar??
Any ideas
tks

JFB

JFB said:
Tks for you reply Morten,
<%# DataBinder.Eval(Container.DataItem, "cfax", "{0:###-###-####}") %>
I try the above code but it's not showing the format in my datagrid and
I
don't get any errors...
Any ideas??
Rgds

JFB




Hi JFB,

I'm sure there is a better method, and using DataBinder.Eval you should
be
able to format the number using something like

[C#]
<%# DataBinder.Eval(Container.DataItem, "cfax", "{0:###-###-####}") %>

However, I was unable to properly format the number that way so an
alternative method is to call a method that formats the number.

[C#]
<%# Format(DataBinder.Eval(Container.DataItem, "fax")) %>

Where Format is defined as


public string Format(object value)
{
long n = Convert.ToInt64(value);
return n.ToString("###-###-####");
}





Hi all,
How can I format a fax number as 888-333-444?
The number is coming from database as 8883334444
<ItemTemplate>
<%#container.dataItem("cfax")%>
</ItemTemplate>

Tks

JFB
 
Never Mine Morten.. it was the empty phone field.
Tks
JFB


I couldn't get it to work either, and it may be because it is not
identified as a number, but the other method should work.


Maybe because phone field is coming as varchar??
Any ideas
tks

JFB

JFB said:
Tks for you reply Morten,
<%# DataBinder.Eval(Container.DataItem, "cfax", "{0:###-###-####}") %>
I try the above code but it's not showing the format in my datagrid and
I
don't get any errors...
Any ideas??
Rgds

JFB




Hi JFB,

I'm sure there is a better method, and using DataBinder.Eval you should
be
able to format the number using something like

[C#]
<%# DataBinder.Eval(Container.DataItem, "cfax", "{0:###-###-####}") %>

However, I was unable to properly format the number that way so an
alternative method is to call a method that formats the number.

[C#]
<%# Format(DataBinder.Eval(Container.DataItem, "fax")) %>

Where Format is defined as


public string Format(object value)
{
long n = Convert.ToInt64(value);
return n.ToString("###-###-####");
}





Hi all,
How can I format a fax number as 888-333-444?
The number is coming from database as 8883334444
<ItemTemplate>
<%#container.dataItem("cfax")%>
</ItemTemplate>

Tks

JFB
 
Back
Top