Click to See Complete Forum and Search --> : [RESOLVED] C# In-Line "If"


adj
01-19-2009, 09:46 AM
Is there a way to do an "if" in-line? Here's the jist of what I want to accomplish (semi-psudo-code)

<asp:Label ID="lblOpt01percent" runat="server" Text='<% # if( totalvotes == 0){ result is 0}else{ do calculations for result } %>' >

I have the calcuations working, except when there are zero totalvotes, then I get a divide by zero error, which is what I'm trying to work around in the above. But when I tried to put the if-statement in, I get an error "Invalid expression term 'if'". Is there another way to accomplish this?

adj
01-20-2009, 10:17 AM
Got it to work, here's the syntax

Text='<% #DataBinder.Eval(Container.DataItem, "totalvotes").ToString()== "0" ? "0" : (do calcuations for result) %>'