0

i'm trying to make an if statment in asp.net. the if statement is done in the listView . but its not working ! all the if statement is been viewed upon runtime

<ItemTemplate>
                <div class="productItem">
                    <div>
                            <img src='<%# Eval("ProductImagePath") %>' alt="<%#Eval("ProductName") %>" height="120"
                                width="120" />
                        </a>
                    </div>
                    <div>
                        <br />
                        <b>
                            <%# Eval("ProductName") %></b>
                            If <%# Eval("CurrentStockQty") %> < 1 || null
                            Then
                                Response.Write("Out of Stock")
                            Else if <%# Eval("CurrentStockQty") %> < 5
                                Response.Write("Less than 5 available")
                            Else
                                Response.Write("In Stock")
                            End If
                            </div>
                </div>
            </ItemTemplate>
3
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by AleMonteiro
0

Create a function in your code block, then from your itemtemplate, call that fuction.

depending on what you are trying to do...

<%# MyFunction(param) %>
<%= MyFunction(param) %>
0

It's not a good implementation what you're trying to do, and I don't know if it can be made like that, I think not.

I'd suggest one of two things: Either do it on the ItemDataBound event on your code behind OR, the easiest one, create a function that return the stock label.

Something like this:

Public Function GetStockLabel(ByVal qty As Int) As String

    If qty < 1 || null
    Then
        Return "Out of Stock"
    Else if qty < 5
        Return "Less than 5 available"
    Else
        Return "In Stock"
    End If

End Function

And call it like this inside <itemtemplate>:

<b><%# Eval("ProductName") %></b>
<%# GetStockLabel(Eval("CurrentStockQty")) %>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.