将标签文本转换为int [英] convert label text to int

查看:94
本文介绍了将标签文本转换为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想将Label文本转换为Integer数据类型.

我尝试通过提供Convert.Int32(Label1.Text)和int.Parse(Label1.Text)
但是我不能做类型转换.我在运行时出错.

我在网络上搜索,但找不到解决方法.

请帮助我....

Hi,

I want to convert Label text into Integer datatype.

I tried by giving Convert.Int32(Label1.Text) and int.Parse(Label1.Text)
but I couldn''t do Type casting . I am getting error at runtime.

I searched in web I couldn''t get the solution.

Please help me....

推荐答案

使用int.TryParse()


这是示例代码:
Use int.TryParse()


Here is a sample code:
string text = Label1.Text; // Say, "10000";
       int number;
       if (int.TryParse(text, out number))
       {
           // It was a number and it has been already assigned to the variable "<code>number</code>"
       }
       else
       {
           //It was not actually a number
       }


<br />
int.TryParse()

是更好的方法,因为如果字符串值实际上不是数字,它在运行时不会抛出任何异常.

is a better way because it won''t throw any exception at runtime if the string value is not actually a number.


Label1.Text="22";
int number = Convert.Int32(Label1.Text)
number=22;

对我来说很好. /> 您遇到什么错误

works fine for me..
what error are you getting


If e.Row.RowIndex <> -1 Then
Dim salary As Integer = CInt(DataBinder.Eval(e.Row.DataItem, "Salary"))
Dim da As Double = Integer.Parse(salary) * (10 / 100)
e.Row.Cells(e.Row.Cells.Count - 2).Text = da.ToString()
end If


这篇关于将标签文本转换为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆