Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
hi i want incement texbox value
like
gpno=txtbox.text+1;
it is possible pls help me
Posted 17-Apr-13 23:02pm
Edited 17-Apr-13 23:05pm
v3
Comments
Tadit Dash at 18-Apr-13 4:06am
   
What is the datatype of gpno ?
And txtbox.text will always be a string.
hemantrautela at 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.)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Convert the text to a numerical value, and than add one
http://msdn.microsoft.com/en-us/library/f02979c7.aspx[^]
 
Would look something like:
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
}
  Permalink  
Comments
Marcus Kramer at 19-Apr-13 10:21am
   
My 5.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

You should first try to convert the TextBox.Text property from its own string type to int type:
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++;
}
  Permalink  
Comments
Marcus Kramer at 19-Apr-13 10:22am
   
My 5.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

yes you can
 
gpno = Convert.Toint32(txtbox1.text)+1;
  Permalink  
v2
Comments
Amarender1479 at 18-Apr-13 4:16am
   
Thank you sir...
Marcus Kramer at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

If the textbox can contain only numerical values :
 
int value = int.Parse(textBox1.Text) + 1;
 
else use :
 
if (int.TryParse(textBox1.Text, out value))
            {
                value += 1;
            }
  Permalink  
Comments
Thomas Barbare at 19-Apr-13 12:09pm
   
Can you tell me why you downrated this solution ? it's correct or maybe I'm missing something ...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

First get the textbox value in integer variable and than add 1 to it..
int txtboxText = Convert.ToInt32(txt1.Text);
int result = txtboxText + 1;
 
OR U can do this in a single line.
int result = Convert.ToInt32(txtbox.text) + 1;
 
and to restrict user to enter only numeric values to textbox You can use Filtered textbox extender.
  Permalink  
v3
Comments
Khan Ji at 18-Apr-13 5:01am
   
Hey Tadit Dash can u tell me what editing you have done with my answer?? :) Just for general knowledge.
Marcus Kramer at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

int a = Convert.ToInt32(txtbox1.Text)+1;
gpno = a;
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 385
1 Sergey Alexandrovich Kryukov 329
2 CPallini 270
3 DamithSL 214
4 Maciej Los 192
0 OriginalGriff 5,515
1 DamithSL 4,451
2 Maciej Los 3,902
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 18 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100