Custom DropDownList Multiple Items without aspx
-
23-06-2021 - |
Question
I have a custom DropDownList
control built off of a Telerik RadComoBox
. I'm currently trying to get this custom control to emulate another RadComboBox
I have on another page that is capable of showing UserFullName, (Company) in the RadComboBox
drop down by using the following aspx:
<telerik:RadComboBox ID="rcbUsers" runat="server" Width="250px" DropDownWidth="300px" OnSelectedIndexChanged="rcbUsers_SelectedIndexChanged"
HighlightTemplatedItems="true" AutoPostBack="true" Height="400px">
<HeaderTemplate>
<div>
Full Name (Company)
</div>
</HeaderTemplate>
<ItemTemplate>
<div>
<b><%# DataBinder.Eval(Container.DataItem, "FullNameLastFirst") %></b>
(<%# DataBinder.Eval(Container.DataItem, "Company") %>)
</div>
</ItemTemplate>
</telerik:RadComboBox>
Is there anyway for me to imitate this in C# code behind for my custom control? It's a requirement that I not require any aspx besides the tag:
<cc1:UserListBox ID="rcbUserTrained" runat="server" OnPreRender="rcbUserTrained_PreRender"/>
Is this possible to do at the databind or render of the custom control?
Solution
I solved this awhile ago, basically I created a new class called UserListBoxColumns
that inherits ITemplate
. I defined my column structure there and bound the data and built it into my custom radcombobox
by overrideing the CreateChildControls()
method where I assigned the appropriate header/itemtemplate/footer into the comobox:
rcbUserList.HeaderTemplate = new UserListBoxColumns(ListItemType.Header);
rcbUserList.ItemTemplate = new UserListBoxColumns(ListItemType.Item);
rcbUserList.FooterTemplate = new UserListBoxColumns(ListItemType.Footer);
If you're interested email me and I can provide more details.