有时候绑定数据时会需要做些判断,可以使用以下方法判断条件!
<asp:DataList ID="DataList2" runat="server" RepeatColumns="4" Width="100%" RepeatDirection="Horizontal">
<ItemStyle Width="500px" Height="110px" />
<ItemTemplate>
<table style="margin-top: 10px">
<tr>
<td>
<a target="_blank" href='ProductDetail.aspx?productID=<%#Eval("ProductID") %>'>
<img src='<%#"../images/"+Eval("Image").ToString().Substring(0,Eval("Image").ToString().IndexOf("|"))+".jpg" %>'
width="140px" height="150px" border="0">
</a>
</td>
</tr>
<tr>
<td align="left" style="height: 40px" valign="top">
<a target="_blank" href='ProductDetail.aspx?productID=<%#Eval("ProductID") %>'>
<%#Eval("Title") %></a>
</td>
</tr>
<tr>
<td align="left">
本店价:<font color="blue"><asp:Label ID="lblPrice" runat="server" Text='<%#Eval("Price").ToString() %>'></asp:Label>元</font>
</td>
</tr>
<tr>
<td align="left">
会员价:<font color="red"><%if (User.Identity.IsAuthenticated)
{ %>
<%#Eval("MemberPrice") %>
<% }
else
{%>
<%#Convert.ToInt32(Eval("Price"))*0.9 %>
<% }%>元 </font>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>