【发布时间】:2016-08-09 10:01:56
【问题描述】:
我试图让购买和销售网站的用户只能编辑他们出售的产品。我知道了,但结果是现在它显示重复。我是 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>
【问题讨论】:
-
为了获得(更好的)答案,我建议您将代码剥离到 sql 部分,其余部分无用。至于给您一些提示,请尝试改进您的 sql。您正在那里进行连接,这将自动导致多行列出相同的产品(对于每个用户,对于每个项目更新)。您还应该检查此链接:sqlblog.com/blogs/aaron_bertrand/archive/2009/10/08/…
-
@Learner 谢谢。我不确定代码中的问题出在哪里,因此那里有很多问题。
-
我希望你意识到我想帮助你而不是马上给你解决方案(无论如何都很简单)......你花在问这些问题上的时间是一样的就像自己做一个小的研究和学习
标签: c# sql asp.net visual-studio listview