简体   繁体   English

C#ASP.NET列表视图

[英]C# ASP.NET List View

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. 我不是一个非常好的ASP.NET开发人员,我不确定该如何处理。

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. 基本上,如果我有10个结果,则需要在列表中显示10个结果,并且每个按钮和图像根据每个产品结果而有所不同。

The source of data is from another class that was built and runs through a foreach for each product. 数据源来自另一个类,该类已针对每个产品构建并贯穿foreach。 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. 我只是认为我需要指出正确的方向,因为我尝试了一张桌子,但效果不佳。

产品清单样品

Maybe you can try using asp.net table and just add rows with the images dynamically once you iterate your results..check out the control here: 也许您可以尝试使用asp.net表,并在迭代结果后只动态添加带有图像的行。请在此处签出控件:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.table.aspx http://msdn.microsoft.com/zh-CN/library/system.web.ui.webcontrols.table.aspx

and here you have an example to add rows dynamically: 这里有一个动态添加行的示例:

http://msdn.microsoft.com/en-us/library/7bewx260%28v=vs.100%29.aspx http://msdn.microsoft.com/zh-cn/library/7bewx260%28v=vs.100%29.aspx

in each row you can put the controls that you want... 在每一行中,您可以放置​​所需的控件...

Using GridView 使用GridView

 <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 eg List, or DataTable of Product etc., and your collection has these fields 假设您有一个产品集合,例如列表或产品的数据表等,并且您的集合具有这些字段

class Product
{
   //property Title
   //property SmallImageUrl
   //property Weight
}

You can have 你可以有

myGrid.DataSource = <Replace with List of Products collection>;
myGrid.DataBind();

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

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