Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i want incement texbox value
like
C#
gpno=txtbox.text+1;

it is possible pls help me
Posted
Updated 17-Apr-13 22:05pm
v3
Comments
What is the datatype of gpno ?
And txtbox.text will always be a string.
Hemant Singh Rautela 18-Apr-13 4:31am    
I think this not your logical issue, why you need to increment that value, which inserted by user...(what is the logic behind it.)

C#
int a = Convert.ToInt32(txtbox1.Text)+1;
gpno = a;
 
Share this answer
 
First get the textbox value in integer variable and than add 1 to it..
C#
int txtboxText = Convert.ToInt32(txt1.Text);
int result = txtboxText + 1;


OR U can do this in a single line.
C#
int result = Convert.ToInt32(txtbox.text) + 1;


and to restrict user to enter only numeric values to textbox You can use Filtered textbox extender.
 
Share this answer
 
v3
Comments
VICK 18-Apr-13 5:01am    
Hey Tadit Dash can u tell me what editing you have done with my answer?? :) Just for general knowledge.
fjdiewornncalwe 19-Apr-13 10:22am    
My 1. Dangerous to use Convert.ToInt32. Solutions 3 & 4 outline the more appropriate way of handling this.
As well, this basically just a repost of Solution 1.
You should first try to convert the TextBox.Text property from its own string type to int type:
C#
int gpno;
if (int32.TryParse(txtbox.Text, out gpno) == false)
{
  // handle error: Text content does NOT represent a valid int
}
else
{ // succesful parse, here you may increment the value.
  gpno++;
}
 
Share this answer
 
Comments
fjdiewornncalwe 19-Apr-13 10:22am    
My 5.
Convert the text to a numerical value, and than add one
http://msdn.microsoft.com/en-us/library/f02979c7.aspx[^]

Would look something like:
C#
Int32 number = new Int32();
if Int32.TryParse(txtbox.text,number) then
{
//it is a number
gpon = number + 1;
}
else
{
//The value is not a number
}
 
Share this answer
 
Comments
fjdiewornncalwe 19-Apr-13 10:21am    
My 5.
If the textbox can contain only numerical values :

int value = int.Parse(textBox1.Text) + 1;


else use :

C#
if (int.TryParse(textBox1.Text, out value))
            {
                value += 1;
            }
 
Share this answer
 
Comments
Thomas Barbare 19-Apr-13 12:09pm    
Can you tell me why you downrated this solution ? it's correct or maybe I'm missing something ...
yes you can

C#
gpno = Convert.Toint32(txtbox1.text)+1;
 
Share this answer
 
v2
Comments
Amarender1479 18-Apr-13 4:16am    
Thank you sir...
fjdiewornncalwe 19-Apr-13 10:21am    
My 1. This is a very dangerous business to just blindly perform a Convert.ToInt32 call. The safer, more correct way to approach this outlined in Solutions 3 & 4.

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