Nov 26, 2011, 7:37 AM
How to show dollars format on label
Hi,
I am trying to show usdollar format number on the lable. When the page loads its working fine but when i click on the button to assign new value to the lable its not showing in us dollar format..
below is the sample code.. please tell me where am i doing wrong?
thank you.
I am trying to show usdollar format number on the lable. When the page loads its working fine but when i click on the button to assign new value to the lable its not showing in us dollar format..
below is the sample code.. please tell me where am i doing wrong?
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<ext:XScript runat="server">
<script language="javascript" type="text/javascript">
var usDollarFormat = function (lbl, v) {
v = (Math.round((v - 0) * 100)) / 100;
v = (v == Math.floor(v)) ? v + ".00" : ((v * 10 == Math.floor(v * 10)) ? v + "0" : v);
v = String(v);
var ps = v.split('.'),
whole = ps[0],
sub = ps[1] ? '.' + ps[1] : '.00',
r = /(\d+)(\d{3})/;
while (r.test(whole)) {
whole = whole.replace(r, '$1' + ',' + '$2');
}
v = whole + sub;
if (v.charAt(0) == '-') {
return '-$' + v.substr(1);
}
lbl.setFieldLabel("$" + v);
//lbl.setText("$" + v);
return "$" + v;
}
</script>
</ext:XScript>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager runat="server" />
<div>
<ext:Button ID="btnSetDollars" runat="server" Text="Set new dollar value">
<DirectEvents>
<Click OnEvent="btnSetDollars_Click" />
</DirectEvents>
</ext:Button>
<ext:Label ID="lblDollar" runat="server">
<Listeners>
<AfterRender Handler=" var r=usDollarFormat(#{lblDollar},#{lblDollar}.fieldLabel); alert(r);" />
</Listeners>
</ext:Label>
</div>
</form>
</body>
</html>
this is code behindnamespace WebApplication1
{
public partial class DollarLable : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblDollar.FieldLabel = "34567";
}
protected void btnSetDollars_Click(object sender, DirectEventArgs e)
{
lblDollar.FieldLabel = "123456";
}
}
}
is there any other way to achieve my requirement?thank you.