如何在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 = ???
}
}
}
Run Code Online (Sandbox Code Playgroud)
或者有没有其他方法在同一页面上显示总数?
使用
Label2.Text = total.ToString();
Run Code Online (Sandbox Code Playgroud)
要么
Label2.Text = Convert.ToString(total);
Run Code Online (Sandbox Code Playgroud)
因为Text需要一个字符串,所以你必须total通过调用ToString()或将你的整数值转换为字符串Convert.ToString(int).
| 归档时间: |
|
| 查看次数: |
35517 次 |
| 最近记录: |