C#ASP.NET列表视图
我想创建一个有多个产品信息的视图。下面是一个例子的产品上市应该怎么样子。我不知道我是否应该使用一个表并创建一个新表中的每个新产品或者是什么。我不是一个很好的ASP.NET开发人员,我不知道如何处理这一点。
I am trying to create a view with multiple product listing in it. An example is below of how the product listing should look like. I am not sure if I should use a table and create a new table for each new product or what. I am not a very good ASP.NET developer and I am not sure how to approach this.
基本上,如果我有10个结果,我需要在列表中,每个按钮,显示这些10,并根据每个产品结果图像是不同的。
Basically if I have 10 results I need to display 10 of these in a list and each button and image is different based on each product result.
数据的来源是从建成并通过每个产品的foreach运行另一个类。在这个任何指导将是有益的。我只是觉得我需要在正确的方向指出,因为我有一张桌子尝试过了,它不工作很好。
The source of data is from another class that was built and runs through a foreach for each product. Any guidance on this would be helpful. I just think I need to be pointed in the right direction because I tried it with a table and it wasn't working out to well.
<asp:GridView runat="server" ID="myGrid"
OnRowCommand="MyGrid_RowCommand">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<img src='<%# Eval("SmallImageUrl") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<div>Title: <%# Eval("Title") %> </div>
<div>Weight: <%# Eval("Weight") %> </div>
<asp:Button runat="server" ID="GetOfferButton" CommandArgument='<%# Eval("OfferID") %>'></asp:Button>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
假设你有一个产品例如集合列表或产品等的数据表,以及您的收藏有这些领域
Assuming you have a collection of Products e.g. List, or DataTable of Product etc., and your collection has these fields
class Product
{
//property Title
//property SmallImageUrl
//property Weight
}
您可以
myGrid.DataSource = <Replace with List of Products collection>;
myGrid.DataBind();