嗨 我是shailendra singh.任何人都可以帮助我.我为此代码而苦. lblEtotal=(Convert.ToString((lblEW.Text) + (lblEfa1.Text) + (lblEfa11.Text))); 我想将此代码转换为字符串,但标签无法转换.如何将数据,lblEtotal,lblEw,lblEfa1,lblEfa11转换为标签.请帮助我. 感谢您的进步.
Hi I am shailendra singh .any one help me .I am suffering for this code . lblEtotal=(Convert.ToString((lblEW.Text) + (lblEfa1.Text) + (lblEfa11.Text))); I want to covert this code int to string but label cannot covert .how can covert data ,lblEtotal,lblEw,lblEfa1,lblEfa11 are label .please help me . Thanks for advance.
推荐答案将每个文本字段转换为数字,然后将它们加在一起: Convert each Text feild to a number, and then add them together: lblETotal.Text = (int.Parse(lblEW.Text) + int.Parse(lblEfa1.Text) + int.Parse (lblEfa11.Text)).ToString();
[edit]忘记了标签输出中的.Text:O-OriginalGriff [/edit]
[edit]Forgot the .Text on the label output :O - OriginalGriff[/edit]
首先请参见 如果 lblEtotal是一个标签,然后分配为 lblEtotal.Text =您要分配的值. lblEW.Text lblEfa1.Text lblEfa11.Text 将是字符串本身.如果要将它们转换为整数,并将它们的总和分配给lblEtotal. 然后 First see if lblEtotal is a label then assign as lblEtotal.Text=value that you want to assign. lblEW.Text lblEfa1.Text lblEfa11.Text will be string itself.If you want to convert these into integer and sum of these assign to lblEtotal. then lblEtotal.Text=(int.Parse(lblEW.Text) + int.Parse(lblEfa1.Text) + int.Parse(lblEfa11.Text)).ToString();
这是另一种解决方案: Here is another solution : int n1, n2, n3; if (int.TryParse(lblEW.Text, out n1) && int.TryParse(lblEfa1.Text, out n2)) && int.TryParse(lblEfa11.Text, out n3)) lblEtotal.Text= (n1+n2+n3).ToString;
希望对您有所帮助.
Hope it helps.
更多推荐
如何将int类型转换为字符串
发布评论