GentlemenFinn
GentlemenFinn

Reputation: 135

Check Eval() with function

I'm trying to make a function that checks if the price has a discount, and if it does it should output a calculated value, but i can't seem to get it working. Anyone knows what i am doing wrong?

ASP.NET: (Extraction from DB is working as intended)

<%# DiscountFunction(Eval("status"), Eval("price"), Eval("procent"))%>

Code behind:

public string DiscountFunction(string status, string price, string discount)
    {
        if(status == "True") {
            int price2 = Convert.ToInt32(price);
            int discount2 = Convert.ToInt32(discount);
            int calc = (price2 / 100) * discount2;
            int final_calc = pris2-calc;
            return price + " " + final_calc;
        } else {
            return price.ToString();
        }
    }

I'm getting the error that my function contains invalid arguments.

Upvotes: 2

Views: 520

Answers (1)

Amit Singh
Amit Singh

Reputation: 8109

try this...

<%# DiscountFunction(Eval("status").ToString(), Eval("price").ToString(), Eval("procent").ToString())%>

you have to convert to string because Eval function have return object type not string so you have to implicitly convert it to string before passing to your function because it require string type arguments not object type.

Upvotes: 5

Related Questions