Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP .NET MVC3
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 22: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
0 OriginalGriff 200
1 George Jonsson 175
2 Kornfeld Eliyahu Peter 169
3 PIEBALDconsult 110
4 Richard MacCutchan 85
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2014
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