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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top