Cast problem

  • Thread starter Thread starter RP
  • Start date Start date
R

RP

I have a public variable in a class of type 'int'. I want to assign a
text box value to it, but it is giving problem. I attempted following
code:

NewGroup.GroupID = (int) txtGroupID.Text;

It generates an error "cast from string to int ....".
 
RP said:
I have a public variable in a class of type 'int'. I want to assign a
text box value to it, but it is giving problem. I attempted following
code:

NewGroup.GroupID = (int) txtGroupID.Text;

It generates an error "cast from string to int ....".

use
int.TryParse
int.Parse
or Convert.ToInt32
 
Back
Top