Click here to Skip to main content
13,003,589 members (61,664 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
How can i make the data list in mvc3 .I cant do it .pls help me
this is my code in asp

<td colspan="2">
    <asp:DataList ID="DataList1" runat="server" RepeatColumns="5" CellPadding="5" CellSpacing="5">
        <ItemStyle Width="200px" />
        <ItemTemplate>
            <table>
                <tr>
                    <td>
                        <asp:Image ID="imgProduct" runat="server" ImageUrl='<%# Eval("Path") %>' Height="150"
                            Width="150" />
                    </td>
                </tr>
                <tr>
                    <td>
                        Product Name :
                        <asp:Label ID="ProductNameLabel" runat="server" Text='<%# Eval("ProductName") %>' />
                    </td>
                </tr>
                <tr>
                    <td>
                        Price :
                        <asp:Label ID="PriceLabel" runat="server" Text='<%# Eval("Price") %>' />
                    </td>
                </tr>
                <tr>
                    <td>
                        Description :
                        <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>' />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("Id") %>' runat="server"
                            OnClick="LinkButton1_Click">Add to Cart</asp:LinkButton>
                    </td>
                </tr>
            </table>
        </ItemTemplate>
    </asp:DataList>
</td>
Posted 27-Nov-12 21:49pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

ASP.NET MVC has no server controls. you can use a simple foreach loop on your model (you can use a partial view too).

You can create HTML helpers too as an alternative http://www.asp.net/mvc/tutorials/older-versions/views/creating-custom-html-helpers-cs[^]
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Please put like this. For this you can make your own Custom html helper.

@foreach (var item in Model)
{ 
<span>
<table>
                <tr>
                    <td>
                        <img src="@Model.ImageSRC" />
                    </td>
                </tr>
                <tr>
                    <td>
                        @Model.ProductName
                    </td>
                </tr>
                <tr>
                    <td>
                        @Model.Price
                    </td>
                </tr>
                <tr>
                    <td>
                        @Model.Description
                    </td>
                </tr>
                <tr>
                    <td>
                        @Html.ActionLink("Add to cart")
                    </td>
                </tr>
            </table>
        </span>
}


Below are the two useful links
http://www.c-sharpcorner.com/uploadfile/dhananjaycoder/working-with-images-in-Asp-Net-mvc-framework/[^]
http://www.devcurry.com/2012/10/aspnet-mvc-displaying-images-using.html[^]

Hope this helps
  Permalink  
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170626.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100