Reputation: 731
How can I display an integer in a Label? What I am doing is I am calculating the total and I am trying to display it in a label.
public partial class total : System.Web.UI.Page
{
int total;
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Server.HtmlEncode(Request.Cookies["confirm"]["quantity"]);
int quantity = (int)Session["TextBox1Value"];
if (Request.Cookies["user"]["items"] == "Tyres")
{
total = 20 * quantity;
Label2.Text = ???
}
}
}
Or is there any other way to display the total on same page?
Upvotes: 1
Views: 48570
Reputation: 48550
Use
Label2.Text = total.ToString();
OR
Label2.Text = Convert.ToString(total);
Since Text
takes a string so you have to convert your total
integer value to string by calling ToString()
or Convert.ToString(int)
.
Upvotes: 8
Reputation: 1448
You can do it using .ToString() or Convert.ToString() methods.
Label2.Text = total.ToString();
or
Label2.Text = Convert.ToString(total);
Upvotes: 0