Include User Control in Repeater Control

Discussion in 'ASP .Net' started by Willy, Dec 26, 2004.

  1. Willy

    Willy Guest

    Hi There!

    Is there any way to include a User Control (ASCX) in the <ItemTemplate> of
    the ASP.NET Repeater control? To be more exact, I need to include a user
    control AND set some properties of the control based on the binded data.

    For example...

    <asp:Repeater id="Repeater1" runat="server">
    <ItemTemplate>

    <%#DataBinder.Eval(Container.DataItem,
    "UserID")%> <br/>

    <MyControls:UserControl1 id="UserControl1"
    runat="server" TestProperty="" />

    <%#DataBinder.Eval(Container.DataItem,
    "ProductID")%> <br/>

    </ItemTemplate>
    </asp:Repeater>

    I need to set the "TestProperty" of the UserControl1 based on binded data to
    the Repeater control.

    Is that possible? If so how do I do that?

    Thank you all in advance!!!

    willy
     
    Willy, Dec 26, 2004
    #1
    1. Advertising

  2. Willy

    Scott Allen Guest

    Hi Willy:

    You can override the ItemDataBound event, obtain a reference to the
    nested control using the FindControl method, and once you have a
    reference you can programatically set properties on the control.

    Here is an example with a DropDownList and a DataGrid, which follows
    the same plan:

    http://odetocode.com/Articles/231.aspx

    HTH,

    --
    Scott
    http://www.OdeToCode.com/blogs/scott/


    On Sun, 26 Dec 2004 21:30:09 +1300, "Willy"
    <> wrote:

    >Hi There!
    >
    >Is there any way to include a User Control (ASCX) in the <ItemTemplate> of
    >the ASP.NET Repeater control? To be more exact, I need to include a user
    >control AND set some properties of the control based on the binded data.
    >
    >For example...
    >
    > <asp:Repeater id="Repeater1" runat="server">
    > <ItemTemplate>
    >
    > <%#DataBinder.Eval(Container.DataItem,
    >"UserID")%> <br/>
    >
    > <MyControls:UserControl1 id="UserControl1"
    >runat="server" TestProperty="" />
    >
    > <%#DataBinder.Eval(Container.DataItem,
    >"ProductID")%> <br/>
    >
    > </ItemTemplate>
    > </asp:Repeater>
    >
    >I need to set the "TestProperty" of the UserControl1 based on binded data to
    >the Repeater control.
    >
    >Is that possible? If so how do I do that?
    >
    >Thank you all in advance!!!
    >
    >willy
    >
     
    Scott Allen, Dec 26, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MeiMei
    Replies:
    0
    Views:
    579
    MeiMei
    Jan 20, 2004
  2. Replies:
    0
    Views:
    861
  3. bill
    Replies:
    4
    Views:
    2,954
  4. satyajit
    Replies:
    2
    Views:
    2,758
    satyajit
    Aug 21, 2007
  5. Andreas Bogenberger
    Replies:
    3
    Views:
    932
    Andreas Bogenberger
    Feb 22, 2008
Loading...

Share This Page