我的ListView显示重复项
本文关键字:显示 ListView 我的 | 更新日期: 2024-09-22 01:11:21
我试图允许买卖网站的用户只能编辑他们出售的产品。我已经知道了,但现在的结果是它显示了重复。我是Stack Overflow和asp.net的新手,所以如果我没有遵循正确的程序,我很抱歉。
<asp:SqlDataSource ID="itemsjoin" runat="server" ConnectionString = '<%$ConnectionStrings:itemsconnection%>' SelectCommand="SELECT itemsupdate.ID, itemsupdate.itemname, itemsupdate.price, itemsupdate.image, itemsupdate.description, itemsupdate.location, itemsupdate.productID, itemsupdate.userID, producttype.productname
FROM producttype, users, itemsupdate
WHERE ([userID] = @userID)">
<SelectParameters>
<asp:QueryStringParameter Name="userID" QueryStringField="userID" Type="Int32"/>
</SelectParameters>
</asp:SqlDataSource>
<asp:ListView ID="itemsdisplay" runat="server" DataSourceID = "itemsjoin" DataKeyNames="ID">
<ItemTemplate>
<div class="col-md-4">
<div class="itemtext">
</br>
<asp:Label ID="itemname" runat="server" Text='<%# Eval("itemname") %>'></asp:Label></br>
<asp:Label ID="itemprice" runat="server" Text='<%# Eval("price") %>'></asp:Label>
<asp:HyperLink ID="itemhyperlink" runat="server" NavigateUrl='<%#"itemediting.aspx?itemid="+Eval("ID")%>'>
<div class="imgright">
<asp:Image ID="imagepic" runat="server" ImageURL='<%# "../../files/"+Eval("image") %>' width="200px" /></asp:HyperLink>
</div>
</div>
</div>
</ItemTemplate>
</asp:ListView>
只需在查询中添加DISTINCT
SELECT DISTINCT itemsupdate.ID, itemsupdate.itemname, itemsupdate.price, itemsupdate.image, itemsupdate.description, itemsupdate.location, itemsupdate.productID, itemsupdate.userID, producttype.productname
FROM producttype, users, itemsupdate
WHERE ([userID] = @userID)