1

I am tyring to pass two values to a function through an Eval.

My function:

public static string ValidateSalary(int salaryFrom, int salaryTo)
{
    string salary = string.Empty;

    if (salaryFrom == salaryTo)
    {
        salary = "£" + salaryFrom.ToString();
    }
    else 
    {
        salary = "£" + salaryFrom.ToString() + " - £" + salaryTo.ToString();
    }
    return salary;
}

My Eval attempt:

<%# ValidateSalary(Eval("SalaryFrom", "SalaryTo")) %>

My error:

Error   5   No overload for method 'ValidateSalary' takes 1 arguments

I've tried multiple ways of formatting it and I can't figure it out!

3
  • <%# ValidateSalary(Eval("SalaryFrom"), Eval("SalaryTo")) %> Commented Apr 7, 2013 at 15:44
  • I have tried that @caerolus and I get even more erros. Commented Apr 7, 2013 at 15:45
  • @lauw0203 If you see my answer stackoverflow.com/a/15864175/159270 on your previous question, you can notice that you can get any parametre on code behind, just by passing the DataItem Commented Apr 7, 2013 at 16:07

3 Answers 3

1

By sending the DataItem on code behind, you can get any parameter as:

<%#RenderSalaryType(Container.DataItem)%>

and on code behind

protected string RenderSalaryType(object oItem)
{
    int salaryType = (int)DataBinder.Eval(oItem, "SalaryType");
    string salaryFrom = (int)DataBinder.Eval(oItem, "SalaryFrom").ToString();
    string salaryTo = (int)DataBinder.Eval(oItem, "SalaryTo").ToString();

    // rest of your code
}

Similar to https://stackoverflow.com/a/15864175/159270

Sign up to request clarification or add additional context in comments.

Comments

0

You can Pass Like this...

<%# ValidateSalary(Convert.ToInt32(Eval("SalaryFrom")),Convert.ToInt32(Eval("SalaryTo"))) %>

1 Comment

Thanks @amit-singh, I tried using convert on one but not the other, so I was still getting the error!
0

Use Eval twice

<%# ValidateSalary(Convert.ToInt32(Eval("SalaryFrom")), Convert.ToInt32(Eval("SalaryTo")) %>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.