ASP.NET - 如果行数= 1,则不显示结果

时间:2017-09-07 12:21:32

标签: sql asp.net

我有一个带有chid中继器的转发器,现在我的目的是隐藏chid转发器,如果​​它的sqlDataSource的行数= 1,如果更大,我想显示所有结果。我试过了

Visible='<%# ((Repeater)Container.NamingContainer).Items.Count >= 1 %>'

关于子reapter但它只适用于我的主转发器行中的第一个iteam。任何建议

我的部分代码 -

 <div id="image_pic" ClientIDMode="Static" runat="server" >

            <table style="width:100%;margin: 0 auto 0 auto">
                <tr>
                    <td colspan="4">
                <img id="mainpic" data-id='<%#"iimage"+Eval("id") %>'  class="img-rounded" alt="" src='<%#Eval("ppic1") %>' style="width: 100%;max-width:550px; max-height:400px " />

                    </td>

                </tr>
              <tr><td>
                  <div style="padding: 3px; margin: 5px; ">
                             <asp:Repeater ID="Repeater2" runat="server" DataSourceID="thumbs" Visible='<%# ((Repeater)Container.NamingContainer).Items.Count >= 1 %>'><ItemTemplate> 
                      <div id="p1" style="display: inline-block">  


                      <img id="thumbs" alt="" class="img-rounded" src='<%#Eval("thumbs") %>' data-mainpicture='<%#Eval("Picture") %>' style="width: 80px; height: 80px; " /></div>
                         </ItemTemplate></asp:Repeater>    




                             <asp:SqlDataSource ID="thumbs" runat="server" ConnectionString="<%$ ConnectionStrings:myConnection %>" SelectCommand="SELECT * FROM [ProductPictures] WHERE ([Productid] = @Productid)" >
                                 <SelectParameters>
                                     <asp:ControlParameter ControlID="pmap" Name="Productid" PropertyName="Value" Type="Int32" />
                                 </SelectParameters>
                             </asp:SqlDataSource> 

我的查询:

SELECT Picture, Productid, thumbs
from
(
    SELECT Picture, Productid, thumbs
    FROM ProductPictures
    GROUP BY Picture, Productid, thumbs
    HAVING COUNT(Productid) <= 2
) as count
where Productid = 40

1 个答案:

答案 0 :(得分:0)

有一个子查询返回包含多张图片的Productid。结果为JOIN

SELECT Picture, Productid, thumbs
from ProductPictures p
join (SELECT Productid
      FROM ProductPictures
      GROUP BY Productid
      HAVING COUNT(*) > 1) cnt on p.Productid = cnt.Productid