I have two aliased fields in my sql call named Wins (calculated from a sum of wins for one team) and Pct (calculating the percentage of wins form a total # of plays) . While processing the the fields through my gridview and code behind, I get the "Unable
to cast object of type 'System.Int32' to type 'System.String' " if i leave my cast reference to lblSu.Text = (string)... , so when i change to lblSu.Text = (int)... I get the "Cannot implicitly convert type 'int' to 'string' " ?? The Pct (label object lblPct)
is a numeric type , so I would need to do something similar here, but now I'm not sure why I can't convert or cast in this context :
//Wins
Label lblSu = (Label)(e.Row.FindControl("lblSu"));
Chumley Walr...
Member
621 Points
235 Posts
Cannot implicitly convert type 'int' to 'string' & Unable to cast object ...errors
Feb 15, 2012 03:01 PM|LINK
I have two aliased fields in my sql call named Wins (calculated from a sum of wins for one team) and Pct (calculating the percentage of wins form a total # of plays) . While processing the the fields through my gridview and code behind, I get the "Unable to cast object of type 'System.Int32' to type 'System.String' " if i leave my cast reference to lblSu.Text = (string)... , so when i change to lblSu.Text = (int)... I get the "Cannot implicitly convert type 'int' to 'string' " ?? The Pct (label object lblPct) is a numeric type , so I would need to do something similar here, but now I'm not sure why I can't convert or cast in this context :
//Wins
Label lblSu = (Label)(e.Row.FindControl("lblSu"));
if (lblSu != null)
{
lblSu.Text = (string)DataBinder.Eval(e.Row.DataItem, "Win");
}
//Pct
Label lblPct = (Label)(e.Row.FindControl("lblPct"));
if (lblPct != null)
{
lblPct.Text = (string)DataBinder.Eval(e.Row.DataItem, "Pct");
}
????????
TIA
chumley