Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6969621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:36:17+00:00 2026-05-27T16:36:17+00:00

I have a textbox in grid view created dynamically. We can access the user

  • 0

I have a textbox in grid view created dynamically. We can access the user input as text, but how do I check whether the text is of integer type or string type?

if (tx.Text == "")
{
    tx.Text = Convert.ToString(0);
}
if (Convert.ToInt32(tx.Text) > max)
{
    MessageBox.Show("Some Message", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
    tx.Text = Convert.ToString(max);
}

tx is the textbox from which we are accessing the user input through tx.Text.
How can I check the type of the input parameter whether it is Integer or not?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:36:18+00:00Added an answer on May 27, 2026 at 4:36 pm

    You’re looking for the TryParse method. That will tell you if a given string value can be converted into a number. And it does it all without throwing any exceptions.

    Sample code:

      int number;
      bool result = Int32.TryParse(tx.Text, out number);
      if (result)
      {
          // Conversion to a number was successful.
          // The number variable contains your value.        
      }
      else
      {
         // Conversion to a number failed.
         // The value entered in the textbox is not numeric.
      }
    

    But if you’re looking to restrict the input range of the textbox (i.e., prevent the user from entering anything but numbers), this is not the correct way to go about it.

    Instead, you should use a different control, such as a NumericUpDown control, or a MaskedTextBox control. These allow you to prevent the user from entering invalid input in the first place, which is much more user friendly than showing an error after the fact.


    In response to your comment:

    in java you have instanceof keyword to check for object type. eg:- Obj instanceof Integer …How do you check for the object type in C#

    C# has the typeof keyword, but that’s not going to help you here. The problem is, the object you’re checking is an instance of type String. The Text property of the TextBox class always returns an object of type String. This is not VB 6: there are no Variants here. What you’re checking is whether that String value can be converted into an equivalent integral representation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a grid view with a nested text box in it. I would
I have created a gridview for populating data, and some user control (TextBox) to
I have a grid view with three columns and five rows with text item
I have a xaml code: <Grid> <WrapPanel> <TextBox ></TextBox> <Button Content=GetIt /> </WrapPanel> </Grid>
I have a textbox whose input is being handled by jQuery. $('input.Search').bind(keyup, updateSearchTextbox); When
I have a textbox with the Text property bound to a dataset column with
I have a textbox and a link button. When I write some text, select
I have a grid view that is data bound to a dataset. In a
I have a grid view.In this i want balance= total paid leave-paid leave taken
I have a grid view with more than one control (ie. a DropDownList and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.