Principiante de ASP.NET. Diseño de lista

I'm new to ASP.NET and are trying to create a list with content from a database. I have been struggling with GridView, but it seems to give me an headache....

If I want to create a list with data from an database, and do some formatting and tricks with links etc, how should I do it?

For example a hit list on eBay, which has data from several columns, images, links with id:s included etc. http://www.ebay.com/sch/i.html?_from=R40&_trksid=p5197.m570.l1313&_nkw=asp.net&_sacat=See-All-Categories

Which control should I use to create the list, and how do I create the Html on each row?

Appreciates all help I can get!

Thanks//L

preguntado el 03 de mayo de 12 a las 18:05

Do you have to use webforms? Otherwise I would recommend a MVC project instead which would make it easier. -

If you plan to customize your html you could consider using a Repeater control. -

1 Respuestas

As mentioned in my comment, using a Repeater will give you all the flexibility while saving you the trouble to create your html from code-behind.

<asp:Repeater ID="MyRepeater" runat="server">
    <HeaderTemplate>
        <div class="ListDiv">
            <h2>My headline</h2>
    </HeaderTemplate>

    <ItemTemplate>
        <div class="ItemDiv">
            <a href='<%# DataBinder.Eval(Container.DataItem, "ProductLink") %>'>
                <%# DataBinder.Eval(Container.DataItem, "ProductName")%>
            </a>
        </div>
    </ItemTemplate>

    <FooterTemplate>
        </div>
    </FooterTemplate>
</asp:Repeater>

Admittedly MVC is modern and state-of-the-art but may give you a steep learning curve.

People could argue that when new to both WebForms and MVC you should rather embark on learing MVC than WebForms.

If you need to deliver something, imho WebForms will give you results faster (when new to ASP.NET in general).

contestado el 03 de mayo de 12 a las 19:05

Aha, a repeter. Havent seen that before. I have a WebForms project. Have looked into MVC but it seemed complicated. Actually I have been programming ASP a long time ago (before ASP.NET). Lately a lot of C++, but when I know try ASP.NET, I am completely lost. I guess I have to get used to the new ways of doing things.... - Lars

If you're coming from an ASP-Classic background you may find MVC not too alien - that's at least what the MVC evangelists claim. I did a lot of ASP-Classic some years ago myself but I didn't get my head around MVC yet. But I have to admit I didn't put much time into learning since I didn't have any project that required it. Basically ASP.NET WebForms are very much built like WinForms apps: Just plug together some controls that do what you need and wire up the event handlers in your code behind. - Filburt

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.