Click here to Skip to main content
15,887,338 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I hav a textbox... I want textbox to accept only numbers 0 to 9 and decimal point. So I'm able to make the textbox to accept only numbers with the following but its not accepting the decimal point...How can i do it...

C#
private void txtVanRef_KeyPress(object sender, KeyPressEventArgs e)
{
          if (!char.IsDigit(e.KeyChar))
              e.Handled = true;

}
Posted

1 solution

if (!char.IsDigit(e.KeyChar) && e.KeyChar!=46)<br />
e.Handled = true;
 
Share this answer
 
Comments
krishna kishore58 6-Dec-10 1:44am    
Hi, thanks its working... One small issue ...in the gridview no matter in which column or in which cell... if i try to enter letters it should not accept...in other way if i enter numbers 0 to 9 and decimal point...then it should accept...I wrote the code in gridview keypress eventbut its not working...can u help me...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900