简体   繁体   English

带有 DataBinder.Eval 的 if 语句

[英]if statement with DataBinder.Eval

the code :编码 :

<asp:Repeater ID="Repeater2" runat="server">
  <HeaderTemplate>
    <table cellspacing="0" cellpadding="0" border="0" width="100%">
  </HeaderTemplate>
  <ItemTemplate>
    <tr>
    <td colspan="3" style="height: 1px; width: 100%; " align="center">
    <div style="height: 1px; width: 90%; background-color: #cccccc;"></div>
    </td>
    </tr>
       <% if (DataBinder.Eval(Container.DataItem, "productID").ToString() == "32668" || DataBinder.Eval(Container.DataItem, "productID").ToString() == "33829" || DataBinder.Eval(Container.DataItem, "productID").ToString() == "33831")
          { %>

    <tr>
      <td style="height: 132px; width: 25%; padding-left:20px;"><a href='product_detail_<%# DataBinder.Eval(Container.DataItem, "productID")%>.aspx'> <img src='<%= System.Configuration.ConfigurationManager.AppSettings["ProductImageUrl"] %>t_<%# DataBinder.Eval(Container.DataItem, "ProductImg")%>'
                                        border="0" /></a> </td>
      <td align="left" valign="top"><br>
        <a href='product_detail_<%# DataBinder.Eval(Container.DataItem, "productID")%>.aspx'> <font color="#000000"><b> <%# DataBinder.Eval(Container.DataItem, "ProductName")%> </b></font></a> <br />
        <br />
        <span class="detailSpan"> <%# DataBinder.Eval(Container.DataItem, "shortDesc")%> </span></td>
      <td style="width: 15%;" align="center"><b> <%# WebDirectBrands.Utility.FormatNumber(Convert.ToDecimal(DataBinder.Eval(Container.DataItem, "ProductPrice")))%> </b> <br />
        <br />
        <a href='product_detail_<%# DataBinder.Eval(Container.DataItem, "productID")%>.aspx'> <img src="images/Details-Link.gif" border="0" /></a> <br />
        <a href='add_to_cart.aspx?productid=<%# DataBinder.Eval(Container.DataItem, "productID")%>'> <img src="images/AddtoCart-Link.gif" border="0" style="margin-top: 5px;" /></a> </td>
    </tr>
      <% } %>
    <tr>
      <td colspan="3" height="15px"></td>
    </tr>
  </ItemTemplate>
  <FooterTemplate>
    </table>
  </FooterTemplate>
</asp:Repeater>

So I have like 40 items, and I want to show just 3 in Featured products.所以我有 40 件商品,我只想在特色产品中展示 3 件。 I wanted to use if statement and operator ||我想使用 if 语句和运算符 || but the problem is DataBinder.Eval .I did't find answer that can help me.但问题是 DataBinder.Eval 。我没有找到可以帮助我的答案。 Can someone help me?有人能帮我吗? Is there some shorter solution with "short if "(a == c ? b : c) or some solution wihtout asp:repeater :)是否有一些更短的解决方案“short if”(a == c ? b : c) 或一些没有 asp:repeater 的解决方案:)

Filtering the data before binding to the repeater will be the optimal solution.在绑定到转发器之前过滤数据将是最佳解决方案。 However you could subscribe to the ItemDataBound event and decide to hide or display the particular item on the fly.但是,您可以订阅 ItemDataBound 事件并决定动态隐藏或显示特定项目。

See this link on MSDN 请参阅 MSDN 上的此链接

In the event handler you can then probably do在事件处理程序中,您可能可以这样做

e.Item.Visible = false;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM