hi all,
i want a textbox for cost purpose which should accept dot before last two digits
u can use this
Listing 1 - Overriding the KeyPress event
protected override void OnKeyPress(KeyPressEventArgs e) { if (e.KeyChar >= '0' && e.KeyChar <= '9') { // move all digits over to the left Shift(); // make sure there is a prompt to replace int index = this.Text.LastIndexOf(PromptChar); if (index >= 0) { // insert the character typed into the last prompt character of the Text string this.Text = this.Text.Substring(0, index) + e.KeyChar + this.Text.Substring(index); } } base.OnKeyPress(e); }
http://www.dotnetheaven.com/Uploadfile/mgold/MaskedCurrencyTextBox02252006005553AM/MaskedCurrencyTextBox.aspx
http://www.c-sharpcorner.com/UploadFile/jibinpan/MaskedTextBoxControl11302005051817AM/MaskedTextBoxControl.aspx
if u are using latest version of vs.net 3.0 then there are one mask property of textbox , where u can set for input format as
MaskedTextBox.Mask = "####.##"
source is here http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.mask.aspx
You can use the RegularExpressionValidator for your TextBox. Here's a link to know more about the Regular Expression Validator:
http://msdn.microsoft.com/en-us/library/ms998267.aspx
From that link, you can use this as your validator: ^\d+(\.\d\d)?$
Regards,SQL Server Helper