I have an integer stored in my database that I need to convert string.
This is my attempt at the Eval:
<%# ChangeSalaryType(Eval(\"SalaryType\"))
Even though you know that the SalaryType
field will be an int
in your aspx it will be cast as object
after the Eval(). Do an explicit cast like so:
<%# ChangeSalaryType(Convert.ToInt32(Eval("SalaryType"))) %>
Try to convert to int
on your Eval part;
Convert.ToInt32(Eval("SalaryType"))
Eval
probably return object
as a return type.
I prefer to send the DataItem on code behind, and there get the data as:
<%#RenderSalaryType(Container.DataItem)%>
and on code behind
protected string RenderSalaryType(object oItem)
{
int salaryType = (int)DataBinder.Eval(oItem, "SalaryType");
// rest of your code
}