How do you pass a DataBinder.Eval Container.DataItem to a functoin?

J

Jeremy

I'm trying to pass a value from a data repeater to a function in my
code behind page. The value is a decimal that i want to show either
in red or black if the number has a negative or positive value.

This works just fine if I try <%redBlack(Convert.ToDecimal(23.5);%>

But when I try to wrap it around the data control i keep getting this
error "CS1026: ) expected"

<%# redBlack(Convert.ToDecimal(DataBinder.Eval (Container.DataItem,
"BuyInAmount"));%>

public void redBlack(decimal intValue)
{
if (intValue < 0)
{
Response.Write("red"+intValue);
}
else
{
Response.Write("black"+intValue);
}
}

I can do something similar to this with a string? Would i have to
convert it to a string, then back to a decimal?

Thanks,
Jeremy
 
D

Dave Rothgery

I'm surprised the first works.
Count your opening and closing parens again -- the number of '('s and ')'s
should always be equal.
 
J

Janaka

This would also work:
<%redBlack(Convert.ToDecimal(((DbDataRecord)Container.DataItem)["BuyInAmount
"]));%>

Using this method is more performance effective than DataBinder.Eval()

Janaka
 
J

Jeremy

Sorry That was just a type-O, even with equal () I keep gettting the
same error "CS1026: ) expected"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top