This is a migrated thread and some comments may be shown as answers.

UserControl inside a RadListBox ItemTemplate

3 Answers 187 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Tommy
Top achievements
Rank 1
Tommy asked on 14 Sep 2012, 07:47 PM
Hi, 

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

Tom

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 17 Sep 2012, 09:14 AM
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.
0
Tommy
Top achievements
Rank 1
answered on 17 Sep 2012, 01:45 PM
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
0
Princy
Top achievements
Rank 2
answered on 18 Sep 2012, 04:27 AM
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.
Tags
ListBox
Asked by
Tommy
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Tommy
Top achievements
Rank 1
Share this question
or