You must Sign In to post a response.
  • Category: ASP.NET

    Converting Numerical to Text in a label


    If you are confused about conversion of Bit Value or Integer value to readable format in string, such as True or False? Read this thread to know more.



    I have a string strScore which will act as label later on and the value in the database is 1 or 2,

    How can I display in a label the value small or large instead of 1 or 2.


    here is the example that shows strscore as 1 or 2 I want is small or large to display

    tblEmpCell2.Text = strScore;

    Regards,
  • #735848

    Please try the below code assuming that strScore contains the value 1.
    string strScore = "1";
    tblEmpCell2.Text=strScore== "1" ? "Small" : "Large";

    if the value in strScore can also be an empty string then follow below code:
    tblEmpCell2.Text = strScore == "1" ? "Small" : strScore=="2"? "Large":"";


    Miss. Jain
    Microsoft Certified Technology Specialist in .Net

  • #735856

    You can use condition, if else, ternary operator to display the value in the label



    if(strScore =="2")
    label1.Text = "Large";
    else
    Lable.Text = "small";




    Label1.Text = strScore =="1" ? "Small" : "Large" ;


    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #735862
    Hi Priya,

    I have this string strScore = string.empty

    would that be possible that the value will be substitute by that text?

  • #735871
    Thank you I got the two as the best answer :) Great!

  • #735882
    Hi Sony,
    Initially As per your question , we were displaying small instead of 1 and large instead of 2, now for empty string which value you want to display?

    Miss. Jain
    Microsoft Certified Technology Specialist in .Net

  • #735889
    According to your title of thread Converting Numerical to Text in a label , You need to use Int32.Parse() for convert string to numeric value. Like below
    string examplestring = "100";  
    int exampleNumber = Int32.Parse(exampleString);
    Or
    You can try this
    Label1.Text = (int.parse(Labe2.Text)+int.parse(Label.Text)).toString();


  • Sign In to post your comments