Converting value of an Eval from int to string

后端 未结 3 951
广开言路
广开言路 2021-01-12 21:40

I have an integer stored in my database that I need to convert string.

This is my attempt at the Eval:

<%# ChangeSalaryType(Eval(\"SalaryType\"))          


        
相关标签:
3条回答
  • 2021-01-12 22:04

    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"))) %>
    
    0 讨论(0)
  • 2021-01-12 22:07

    Try to convert to int on your Eval part;

    Convert.ToInt32(Eval("SalaryType"))
    

    Eval probably return object as a return type.

    0 讨论(0)
  • 2021-01-12 22:26

    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
    }
    
    0 讨论(0)
提交回复
热议问题