Bind LinQ Results to Repeater Control (without LinqToSQL datasource)

Last post 07-09-2008 3:26 PM by urtlking2jo. 3 replies.

Sort Posts:

  • Bind LinQ Results to Repeater Control (without LinqToSQL datasource)

    07-09-2008, 3:03 PM

    Hello - 

    I am trying to bind data retrieved in the code-behind using Linq to a repeater control on the presentation layer.  How do I access the objects stored in 'results' on the presentation layer?  Basically, what needs to go between the <% %> on the aspx file?  Thanks!!


            protected void Page_Load(object sender, EventArgs e)
            {
                MilitaryAvenueDataContext db = new MilitaryAvenueDataContext();
                var results = from l in db.PartnerListings where l.StatusID == 3 && l.InstallationID == 1 select l;

                Repeater1.DataSource = results;
                Repeater1.DataBind();

            }

     

    <form id="form1" runat="server">
        <div>
            <asp:Repeater ID="Repeater1" runat="server">
                <HeaderTemplate>
                    Header Info Here</HeaderTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text="<% %>"></asp:Label></ItemTemplate>
                <FooterTemplate>
                    Footer Info Here</FooterTemplate>
            </asp:Repeater>
        </div>
        </form>

    Filed under: , ,
  • Re: Bind LinQ Results to Repeater Control (without LinqToSQL datasource)

    07-09-2008, 3:12 PM
    Answer
    • Loading...
    • Jeev
    • Joined on 11-24-2005, 12:49 PM
    • Posts 3,139

    Eg to display installation id

    <asp:Label ID="Label1" runat="server" Text='<%# Eval("InstallationID") %>'></asp:Label></ItemTemplate>

    Jeev
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    If you get the answer to your question, please mark it as the answer.
  • Re: Bind LinQ Results to Repeater Control (without LinqToSQL datasource)

    07-09-2008, 3:13 PM
    Answer
    • Loading...
    • ecbruck
    • Joined on 12-30-2005, 2:39 PM
    • Des Moines, IA
    • Posts 7,995
    • Moderator
      TrustedFriends-MVPs

    You'd simply enter a data-binding expression for a field within your PartnerListings table like so:

    <asp:label id="Label1" runat="server" text='<%# Eval("StatusID") %>' />

    Thanks, Ed

    Microsoft MVP - ASP/ASP.NET

  • Re: Bind LinQ Results to Repeater Control (without LinqToSQL datasource)

    07-09-2008, 3:26 PM

     Thank you both... I don't know why I was thinking it would be more complex than that!  I guess we all have our moments :-)

Page 1 of 1 (4 items)
Microsoft Communities
Page view counter