Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Converting label to string to integer in C# error

Hi Guys,
i have 3 lable controls in my ASPX page and in my codebehind
i'm getting them as follows:-
Label survid = (Label)e.Item.FindControl("surveyid");
Label percid = (Label)e.Item.FindControl("percentage");
Label linkid = (Label)e.Item.FindControl("link");

But i want to convert the percid,survid and linkid to integer in C# but no luck.
The percid here would sometime be a float for example 16.67 as below how can i get it
as a label as above convert it to double and then use it.

I want to use the values in OnItemCreated as show below but no LUCK converting it to integer and the percentage value to double
any ideas?
Thanks in advance

public void GetLinksItemCreated(object sender,DataGridItemEventArgs e)
//{

{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)

{
Label survid = (Label)e.Item.FindControl("surveyid");
Label percid = (Label)e.Item.FindControl("Allperc");
Label linkid = (Label)e.Item.FindControl("link");

//string perc = percid.Text;
//int perc1 = Convert.ToInt32(percid.ToString());
//percid.ToString();
double perc1 = 16.67;
//perc1 = Int32.Parse(perc.ToString());
int surv = Int32.Parse(survid.Text);
Response.Write(surv);

{



if (perc1 >= 16.67)
{
linkid.Text = "You've Passed";

}
else
if (perc1 < 16.67)
{
//linkid.Text = "<a href='http://bbb/NSurvey_WebAdmin/survey.aspx?surveyid=" + surv + "' style='text-decoration: underline;'><b>" + surv + "</b></a>";
linkid.Text="-";
}


}


}
}
[1926 byte] By [naijacoder] at [2007-11-11 7:52:34]
# 1 Re: Converting label to string to integer in C# error
Label survid = (Label)e.Item.FindControl("surveyid");
Label percid = (Label)e.Item.FindControl("Allperc");
Label linkid = (Label)e.Item.FindControl("link");

int surv = Int32.Parse(survid.Text);
double perc = Double.Parse(percid.Text);
int link = Int32.Parse(linkid.Text);

Does that work? If not, what happens?
Phil Weber at 2007-11-11 23:13:30 >
# 2 Re: Converting label to string to integer in C# error
Thx Phil..
I got it going
Guess i was just too yesterday(Just didn't see)
naijacoder at 2007-11-11 23:14:36 >