Skip to content

Display Variable Values

Shaun

Asked Apr 30, 2007, 12:15 PM EDT3 answers
Share
LinkedInX
If i would like to take an interger value and display it on a label control, within a string, how do I accomplish this? 

Ex.
Read an input from textbox1.Text and have a label display "The input from the textbox is:          "  The actual value of TextBox1.Text should go after the colon.  How is this accomplished in C#.NEt ?

Thank You

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    ok if your taking a value from a textbox's text property that value will be a string so

    lblsomeLabel.Text = textbox1.Text;

    would work.
    however if you wanted the value of textbox1.Text to be of type int you would have to call the conversion of the text property

    // declare variable
    int value;

    // parse the .text property to type int and set variable equal to the resultant int value
    value = int.parse(textbox1.Text);

    // get lblsomeLabel to display the int variable by calling the tostring method.
    lblsomeLabel.Text = "The input from the textbox is: " + value.tostring()

    Hope this helps im still learning myself

    Jay
    0
  • 0
    Thank you very much, that was exactly what I was looking for.  Thanks!
    0
  • 0
    no problem glad i could help

    Jay
    0