0

I need to use triple nested if statement using ASP.NET Web forms binding expression. I have tried the following:

<asp:TemplateField HeaderText="Price">
                                      <ItemTemplate>
                                          $ <%# Convert.ToBoolean(Eval("TierPricing")) ? Eval("PraviTier") + " per feet" : Convert.ToBoolean(Eval("IsPricingIndex")) ? Eval("ProductTierPrice") + " per feet" : Convert.ToString(Eval("SubCategoryName"))=="Custom kits" ? Eval("Price") + " per feet" : Eval("Price") + " per package"  %></p>
                                      </ItemTemplate>
                                  </asp:TemplateField>

The problem arises with first if statement, its not writing the value I want it to write ... :/ Can someone help me out how to format this if statement properly??

Eval("PraviTier") should write - 1.5 Eval("ProductTierPrice") should write - 1.25

Instead Eval("PraviTier") is writing 1.25 value... why is that???

Here is a picture showing what I mean:

enter image description here

Any hints??

P.S. Its as if the first If statement is completely ignored?!

Edit: I've checked what does the stored procedure returns... Eval("TierPricing") is set to true in database... so what could possibly be the issue here? :/

perkes456
  • 1,163
  • 4
  • 25
  • 49
  • *its not writing the value I want it to write* Please be more clear. What is it you expect, and what is actually happening? – Drew Kennedy Jan 31 '16 at 21:02
  • Your code *looks* correct. Can you create a [mcve] of your nested expression (ideally without ASP.NET and with the concrete truth values plugged in) that reproduces the issue? (Hint: If your toy example works, gradually remove the difference between the toy example and your real code until you find out what is causing the problem. Then come back and tell us.) – Heinzi Jan 31 '16 at 21:03
  • Hey guys, I've updated my first post, please check it out? – perkes456 Jan 31 '16 at 21:10
  • Guys ? Any ideas ? I'm totally worn out of any ideas...I've no ideas why it doesn't works :/ – perkes456 Jan 31 '16 at 21:21

1 Answers1

0

Okay I've solved the puzzle.... Apparently this is the right way to do the logic that I needed:

  <asp:TemplateField HeaderText="Price">
                                      <ItemTemplate>
                                          <%# Eval("PraviTier") %>
                                          $ <%# Convert.ToBoolean(Eval("IsPricingIndex")) ? Eval("PraviTier") + " per feet" : Convert.ToBoolean(Eval("TierPricing")) ? Eval("ProductTierPrice") + " per feet" : Convert.ToString(Eval("SubCategoryName"))=="Custom kits" ? Eval("Price") + " per feet" : Eval("Price") + " per package"  %></p>
                                      </ItemTemplate>
                                  </asp:TemplateField>

This answer can serve as a guide for someone who may need nested if statements using asp.net binding expressions in the future... :-)

perkes456
  • 1,163
  • 4
  • 25
  • 49