2 easier questions

davearia

Centurion
Joined
Jan 4, 2005
Messages
184
Hi All,

I have 2 more easier questions I would like to ask:

1. How in code do you set a textbox on an ASP.NET page to get focus? (I have looked on the web and such also used the intellisense but no luck)

2. How do I format a string to currency? (So that if there is any decimal values they are always 2 decimal places or if there is no decimal values show no decimal places)

I have had two attempts:
Code:
lblQuote.Text = "Charge for walls = £" + String.Format("{0:C}", Convert.ToString(wallCost))
Code:
lblQuote.Text = "Charge for walls = £" + String.Format("{0:F2}", Convert.ToString(wallCost))
These work in as much as they only allow 2 decimal places maximum, however they would display £10.10 as £10.1. How can I avoid this?

Many thanks, Dave. :D
 
Looking at an older project I may have set focus like this:
Code:
strScript = "<script language=javascript> document.all('txtJumpTo').focus() </script>"
RegisterStartupScript("focus", strScript)
 
This worked for me:
Dim p as Double = "1234,10"
output.Text = p.ToString("c")

where output is a label, the important is the "c" parameter used in the ToString function, it formatted the number into currency, and respected the ending zero.
 
Back
Top