IT Community - Software Programming, Web Development and Technical Support

How to cast the value entered in a textbox to integer in ASP.NET and C# .Net.

This is a discussion on How to cast the value entered in a textbox to integer in ASP.NET and C# .Net. within the ASP and ASP.NET Programming forums, part of the Web Development category; Hi All.... can anyone guide me, How to cast the value entered in a textbox to integer in ASP.NET ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > ASP and ASP.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 09-20-2007, 05:17 AM
a.deeban a.deeban is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 279
a.deeban is on a distinguished road
Default How to cast the value entered in a textbox to integer in ASP.NET and C# .Net.

Hi All....

can anyone guide me, How to cast the value entered in a textbox to integer in ASP.NET and C# .Net.

thanks in advance....


thnx...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-20-2007, 05:23 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Default Re: How to cast the value entered in a textbox to integer in ASP.NET and C# .Net.

Hi Deeban,

you can convert using Int32.Parse(TextBox1.Text);

or by using System.Convert.ToInt32(TextBox1.Text);


thanks...
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-20-2007, 05:31 AM
a.deeban a.deeban is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 279
a.deeban is on a distinguished road
Default How to allow only numeric values in a textbox using ASP.NET Validator control?

Hi Sathish....

thanks for your reply i have one more doubt....

How to allow only numeric values in a textbox using ASP.NET Validator control?


thanks in advance...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-20-2007, 05:33 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Default Re: How to cast the value entered in a textbox to integer in ASP.NET and C# .Net.

Hi Deeban...

you can do this by using regular expression and here is the sample piece of code...


<asp:TextBox id="txtNumber" Runat="server" />

<asp:RegularExpressionValidator ID="vldNumber" ControlToValidate="txtNumber" Display="Dynamic" ErrorMessage="Not a number" ValidationExpression="(^([0-9]*|\d*\d{1}?\d*)$)" Runat="server">

</asp:RegularExpressionValidator>



i hope this will help you...
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 09-20-2007, 05:35 AM
a.deeban a.deeban is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 279
a.deeban is on a distinguished road
Default How to align the Text property of the Textbox Control using c# ASP. Net?

Hey sathish..

thanks for your reply....and one more doubt...

How to align the Text property of the Textbox Control using c# ASP. Net?


thanks...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 09-20-2007, 05:36 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Default Re: How to cast the value entered in a textbox to integer in ASP.NET and C# .Net.

hi Deeban....

you can simple set the style property by "right, left,...."

TextBox1.Style["text-align"]="right";

thnx...
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 09-20-2007, 05:48 AM
a.deeban a.deeban is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 279
a.deeban is on a distinguished road
Default How can I read the text from the dataset and assign it to textbox1.text in C# .Net ?

Hi Sathish...

I am running the query SQL="Select name from profile where proID=1"; and I am getting the result in Dataset dsdata. How can I read the text from the dataset and assign it to textbox1.text ?


thanks in advance....
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 09-20-2007, 05:56 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Default Re: How to cast the value entered in a textbox to integer in ASP.NET and C# .Net.

Hi Deeban...

here is the code for your question..

TextBox1.Text=dsData.Tables[0].Rows[0]["FieldName"].ToString();

thanks..
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 09-20-2007, 05:58 AM
a.deeban a.deeban is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 279
a.deeban is on a distinguished road
Default Option Strict On disallows implicit conversions from 'System.Web.UI.Control' to 'Syst

Hi Sathish...

Why do I get error message "Option Strict On disallows implicit conversions from 'System.Web.UI.Control' to 'System.Web.UI.WebControls.TextBox'."?


can you give me any solution...?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 09-20-2007, 05:59 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Default Re: How to cast the value entered in a textbox to integer in ASP.NET and C# .Net.

Hi Deeban,

For type Casting apply the following steps

string aprtxt;
aprtxt = (TextBox) e.Item.FindControl["txtapr"];

i hope this will help you...
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 09-20-2007, 06:00 AM
a.deeban a.deeban is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 279
a.deeban is on a distinguished road
Default Re: How to cast the value entered in a textbox to integer in ASP.NET and C# .Net.

thank you sathish....

thank you very much for your help...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you limit the length (in characters) of text entered in a textarea form field GDevakii HTML, CSS and Javascript Coding Techniques 2 03-24-2008 08:41 PM
How do I check that text entered in a text form field is an integer? itbarota HTML, CSS and Javascript Coding Techniques 2 10-26-2007 12:25 AM
How to create textbox without border? ramkumaraol PHP Programming 2 09-07-2007 06:13 AM
Java handle integer overflows and underflows vigneshgets Java Programming 1 07-12-2007 12:12 AM
Convert integer type variable to char array oyu2o C and C++ Programming 0 03-10-2007 09:47 AM


All times are GMT -7. The time now is 02:54 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0