UserControl inside a RadListBox ItemTemplate

4 posts, 0 answers
  1. Tommy
    Tommy avatar
    30 posts
    Member since:
    Nov 2011

    Posted 14 Sep 2012 Link to this post

    Hi, 

    can we use a user control as an itemtemplate inside a radlistbox as we do it with the radgrid?

    Tom
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 17 Sep 2012 Link to this post

    Hi Tommy,

    You can add user control inside the RadListBox ItemTemplate as follows.

    ASPX:
    <telerik:RadListBox ID="RadListBox1" runat="server">
        <Items>
               <telerik:RadListBoxItem Text="RadListBoxItem" />
        </Items>
        <ItemTemplate>
               <uc1:userwindow ID="userwindow1" runat="server" />
        </ItemTemplate>
    </telerik:RadListBox>

    Hope this helps.

    Regards,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tommy
    Tommy avatar
    30 posts
    Member since:
    Nov 2011

    Posted 17 Sep 2012 Link to this post

    Hi Princy,

    yes I can use my template like you said, but how can I set values in my user control? When I add an item, I did not found a way to access the user control instance.

    thanks

    Tom
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 17 Sep 2012 Link to this post

    Hi Tommy,

    I suppose you want to access the UserControl in server side. Try accessing the UserControl as follows.

    ASCX:
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

    ASPX:
    <telerik:RadListBox ID="RadListBox1" runat="server">
       <Items>
          <telerik:RadListBoxItem Text="RadListBoxItem" />
       </Items>
       <ItemTemplate>
          <uc1:userwindow ID="userwindow1" runat="server" />
       </ItemTemplate>
    </telerik:RadListBox>

    C#:
    UserControl userwindow1 = (UserControl)RadListBox1.Items[0].FindControl("userwindow1");
    TextBox TextBox1 = userwindow1.FindControl("TextBox1") as TextBox;
    TextBox1.Text = "Your Text";

    Please elaborate your scenario if it doesn't helps.

    Regards,
    Princy.
Back to Top