954,577 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Convert text to int

Hi all , I am a newbie here, excited to join in this community. Here I have a question reg asp.net and MSaccess.
My application runs on asp.net with msaccess as backend. I need to implement a search, search by studentID which is an int. The user will put a studentID in the textbox and hit search button, it should search all details pertaining to the studentID in msaccess and should retrieve results in FORMVIEW/ EDITitem template(DAFAULT setting). So when i put studentID in textbox it takes as a string, how can i convert string to int and where? in C# pageLoad method? or searchbutton_click method? and how can i get the results back to formview? I would really appreciate your help
Thank You

venkatad
Newbie Poster
1 post since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

Hello Venkatad!

If I were you I'd use the searchbutton_click method, get the text directly from the textbox, then do the convert. The code is:

try{
Convert.ToInt32(StudentId.Text)
}
catch(FormatException)
{
//warn if the box contains characters which are not numeric..
}


However if the textbox is inside a formview, you may encounter an error like "Target is not instance of an object, etc", so first you have to find the box.
The code would be something similar: TextBox StudentId = (TextBox) FormView1.(ItemTemplate).FindControl("StudentId");

ItemTemplate is in () because I don't remember if it's necessary..

konczuras
Junior Poster in Training
59 posts since Oct 2008
Reputation Points: 10
Solved Threads: 1
 

There are a couple of ways to do this. I tend to use:

int i=Int32.Parse (<mystring>);

Hope this helps.

-=Sal=-

salientknight
Newbie Poster
3 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

hi,

try like this

int i=int.parse(textbox1.text);
greeny_1984
Posting Whiz
372 posts since Apr 2007
Reputation Points: 25
Solved Threads: 29
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You