Click here to Skip to main content
15,914,820 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
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.
Posted
Updated 20-Dec-11 23:02pm
v2

Convert each Text feild to a number, and then add them together:
C#
lblETotal.Text = (int.Parse(lblEW.Text) + int.Parse(lblEfa1.Text) + int.Parse (lblEfa11.Text)).ToString();


[edit]Forgot the .Text on the label output :O - OriginalGriff[/edit]
 
Share this answer
 
v2
Comments
Ankur\m/ 21-Dec-11 4:48am    
:thumbsup:
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

C#
lblEtotal.Text=(int.Parse(lblEW.Text) + int.Parse(lblEfa1.Text) + int.Parse(lblEfa11.Text)).ToString();
 
Share this answer
 
Here is another solution :
C#
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.
 
Share this answer
 
v2
Comments
Ankur\m/ 21-Dec-11 5:01am    
Does it have any advantages over the method described above?
Amir Mahfoozi 21-Dec-11 5:03am    
Yes, it is error free without using try catch block.
hi try this way

asp:
ASP.NET
<pre lang="xml"><asp:Label ID="lblEW"  runat="server" >1</asp:Label>
      <asp:Label ID="lblEfa1"  runat="server" >2</asp:Label>
        <asp:Label ID="lblEfa11"  runat="server" >2</asp:Label>
                <asp:Label ID="lblEtotal"  runat="server" ></asp:Label>



C#
C#
int ans = Convert.ToInt32(lblEW.Text) + Convert.ToInt32(lblEfa1.Text) + Convert.ToInt32(lblEfa11.Text);
         lblEtotal.Text = Convert.ToString(ans);
         Response.Write(lblEtotal.Text);


output will be
5
 
Share this answer
 
Hello..

lblEtotal.Text==(Convert.ToString(int.Parse(lblEW.Text) + int.Parse(lblEfa1.Text) + int.Parse(lblEfa11.Text)));

OR

int ans= int.Parse(lblEW.Text)+int.Parse(lblEfa11.Text)+int.Parse(lblEfa1.Text)
lblEtotal.Text = Convert.ToString(ans);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900