CodeSmith Community
Your Code. Your Way. Faster!

Bind to First T<List> Entity

Latest post 03-26-2007 7:51 PM by bevan. 4 replies.
  • 03-26-2007 6:11 PM

    • bevan
    • Not Ranked
    • Joined on 03-14-2007
    • Posts 6
    • Points 150

    Bind to First T<List> Entity

    Hi,

    This is a duplicate post but since I'm still searching for an answer I'm posting again.  I apologise but I really need to find a solution to this problem.

    I have a list of Installations, related to an Installation is a list of Images.
    When listing Installations I want to select the 1st Image of the Image list related to the Installation.

    Below is what I currently have, it obviously lists all images.
    I'm guessing I probably shouldn't be using a repeater but I can't figure out how to bind anything else to an image datasource let alone have the datasource return only the 1st image.

            <asp:Repeater ID="rptInstallations" runat="server">
                <ItemTemplate>
                    <div class="installation">
                        <asp:Repeater ID="CategoryID1" runat="server" DataSourceID="ImageFiter">
                            <ItemTemplate>
                                <asp:image id="Image" runat="server" ImageUrl='<%# "Upload/" + Eval("ImageURL") %>' Title='<%#Eval("Caption") %>' />
                            </ItemTemplate>
                        </asp:Repeater>
                        <data:EntityDataSourceFilter ID="ImageFiter" runat="server" DataSourceID="ImageDataSource" Filter='<%# String.Format("ObjectID = {0}", Eval("ID")) %>' />
                </ItemTemplate>
            </asp:Repeater>
            <data:ImageDataSource ID="ImageDataSource" runat="server" SelectMethod="GetAll" />

    This seems like such a simple problem, it's frustrating i can't figure it out.

    Should I be using a custom SP? how?
    Should I be binding to an entity instead of a list? using a dataobjectsource? how?

    Please help.
    • Post Points: 65
  • 03-26-2007 6:34 PM In reply to

    • mduray
    • Top 150 Contributor
    • Joined on 03-15-2007
    • Posts 27
    • Points 525

    Re: Bind to First T&amp;amp;lt;List&amp;amp;gt; Entity

    Reply |Contact |Answer

    Have you considered / tried switching the select method on your datasource to GetPaged, and add a PageSize parameter of 1 and a PageIndex parameter of 0?

    Don't know if that would work (or if you should listen to me -- I'm pretty new to netTiers).

    • Post Points: 35
  • 03-26-2007 7:43 PM In reply to

    • bevan
    • Not Ranked
    • Joined on 03-14-2007
    • Posts 6
    • Points 150

    Re: Bind to First T<List> Entity

    Yes, that works!

    I knew there'd be some simple solution to this!

    Although for some reason PageSize=1 doesn't work, PageSize=2 returns 1 image....
    I'll check my data.

    Thank you

    • Post Points: 5
  • 03-26-2007 7:44 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 726
    • Points 16,910

    Re: Bind to First T<List> Entity

    bevan,

    What you could do is to create a view which would look like this (you'd get all the installations and single image for each):

    SELECT
        *
    FROM 
        Installations i
        INNER JOIN Images m ON i.ImageId = m.ImageId
    WHERE
        m.ImageId=(SELECT top 1 ImageId FROM Installations)

    Include the view in the code generation process and use the typed data source the usual way.

     See if it helps


     

     

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 35
  • 03-26-2007 7:51 PM In reply to

    • bevan
    • Not Ranked
    • Joined on 03-14-2007
    • Posts 6
    • Points 150

    Re: Bind to First T<List> Entity

    Great,

    That seems like a better solution than just changing the pagesize and showing the first page.
    I didn't even think about using a View...

    I will have to give this a go when I get back to development machine later today.

    • Post Points: 5
Page 1 of 1 (5 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems