Click here to Skip to main content
15,908,254 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello, I have created a grid view with multiple text boxes dynamically.
I want those text boxes to enter only numbers in code behind only.
some one suggest me a suitable answer.
Posted
Comments
Thanks7872 1-Oct-13 3:57am    
What is Code behind? What do you mean by C#?

Make them disabled) Something like
C#
myTextBox.Enabled = false;


In this case user would not be able to change value in textbox.

Edit To validate numbers, you should write a method, that will occur when text in textbox is changed (take from events in textbox) and it should check, if there are only numbers or not.
 
Share this answer
 
v3
You can use RegularExpressionValidator for that TextBox.

Refer - Re: How validate in Gridview textbox as numeric[^] for one Example.
 
Share this answer
 
Comments
Shibasankar 1-Oct-13 5:00am    
I want do it completely in code behind...
Then you can go for Soultion 1 by Alexander Dymshyts.

But handling Validations at the client side is a good and better approach.
on click of the grid event write code to check for the text box editing. if both condistion satisfied than you can go for regular expression which allow user to enter only numeric [0-9] something kind of.

in this way you can achieve your desire functionality.

_SG
 
Share this answer
 

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