lundi 2 mars 2015

If statement error in aspx page

I am doing product page and I want there "You maybe need also these products".


For example if productID is 2 then show me link to productID 5.


I have tried to do it with this:



<% if(Item.ProductID == 2) { %>
<a href="ProductDetails.aspx?productID=5">
<img src="/Catalog/Images/suihkukaappi.png"
width="100" height="75" style="border: solid" /></a>
<% } %>


But it give me error "The name 'Item' does not exist in current context." And link works fine if I take this if statement off but same link is every product page.


And here is my code inside ItemTemplate from aspx page:



<ItemTemplate>
<div>
<h1><%#:Item.ProductName %></h1>
</div>
<br />
<table>
<tr>
<td>
<img src="/Catalog/Images<%#:Item.ImagePath %>" style="border:solid; height:150px; width:175px;" alt="<%#:Item.ProductName %>"/>
</td>
<td>&nbsp;</td>
<td style="vertical-align: top; text-align:left;">
<b>Tuoteselostus:</b><br /><%#:Item.Description %>
<br />
<span><b>Hinta:</b>&nbsp;<%#: String.Format("{0:c}", Item.UnitPrice) %></span>
<br />
<span><b>Tuotenumero:</b>&nbsp;<%#:Item.ProductID %></span>
<br />
</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>
<% if(Item.ProductID == 2) { %>
<a href="ProductDetails.aspx?productID=5">
<img src="/Catalog/Images/suihkukaappi.png"
width="100" height="75" style="border: solid" /></a>
<% } %>


</td>
</tr>
</table>
</ItemTemplate>

Aucun commentaire:

Enregistrer un commentaire