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

Need help with ComboBox ItemTemplates

1 Answer 51 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
fred williams
Top achievements
Rank 1
fred williams asked on 10 Nov 2010, 06:47 PM

So I’m using the directoryinfo class to obtain the filenames from a network share, and then display them into my radcombobox. Everything works fine, but what I’d like to do is create a checkbox next to all of the values in the combobox so the user can select multiple files.


When I do it without the itemtemplate, all the filenames display fine, but when I try to use them to add the checkbox, the checkboxes show up but the filenames don’t. Here’s what I have:

<telerik:RadComboBox ID="cboFiles" runat="server" AutoPostBack="true" Width="350px" OnItemDataBound="cboFilesDBound">
     <ItemTemplate>
         <asp:CheckBox ID="chkFile" runat="server" /> 
     </ItemTemplate>
 </telerik:RadComboBox>
What do I need to put next to the checkbox to get the filenames to display? Again, when I do this without the template the filenames show fine. I tried using databinder.eval with some custom attributes like the demo, but it didn't work.

Here's the codebehind:
protected void setDirectory(String path)
{
    RadComboBox cb = (RadComboBox)FindControl("cboFiles");
     
    DirectoryInfo di = new DirectoryInfo(path);
    FileInfo[] files = di.GetFiles();
    foreach (FileInfo f in files)
    {
        RadComboBoxItem item = new RadComboBoxItem(f.Name, f.Name);
        item.Attributes["displayName"] = f.Name;
        cboFiles.Items.Add(item);
    }
 
}


1 Answer, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 16 Nov 2010, 02:20 PM
Hi fred williams,

You need to use data binding expressions inside the ItemTemplate definition to render the additional data as done in the first RadComboBox in this demo.

I hope this helps.

All the best,
Simon
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
ComboBox
Asked by
fred williams
Top achievements
Rank 1
Answers by
Simon
Telerik team
Share this question
or