简体   繁体   中英

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.

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.

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.

产品清单样品

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:

http://msdn.microsoft.com/en-us/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

in each row you can put the controls that you want...

Using 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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