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

Multi Column Combo Box without Data binding

2 Answers 88 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Mo
Top achievements
Rank 1
Mo asked on 03 Aug 2012, 12:45 PM
So I have a items that I need fill into the combo box without having to bind the combo to a table in the database. How do I do that?

2 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 03 Aug 2012, 01:09 PM
Hello,

<telerik:RadComboBox ID="RadComboBox1" runat="server" MarkFirstMatch="true" EmptyMessage="--Select--">
           <HeaderTemplate>
               <table ellspacing="0" cellpadding="0">
                   <tr>
                       <td style="width: 150px;">
                           First Name
                       </td>
                       <td style="width: 150px;">
                           Last Name
                       </td>
                   </tr>
               </table>
           </HeaderTemplate>
           <ItemTemplate>
               <table cellspacing="0" cellpadding="0">
                   <tr>
                       <td style="width: 150px;">
                           <%# DataBinder.Eval(Container, "Attributes['FirstName']")%>
                       </td>
                       <td style="width: 150px;">
                           <%# DataBinder.Eval(Container, "Attributes['LastName']")%>
                       </td>
                   </tr>
               </table>
           </ItemTemplate>
       </telerik:RadComboBox>


protected void bindCombo()
    {
       
        for (int i = 0; i < 10; i++)
        {
            RadComboBoxItem item = new RadComboBoxItem();
 
            item.Text = i + "Text";
            item.Value = i + "Value";
            item.Attributes.Add("FirstName", i + "FirstName");
            item.Attributes.Add("LastName", i + "LastName");
 
            RadComboBox1.Items.Add(item);
 
            item.DataBind();
        }
    }



Thanks,
Jayesh Goyani
0
Nencho
Telerik team
answered on 06 Aug 2012, 07:49 AM
Hi Mohamed,

In order to achieve the desired functionality, you could create your own RadComboBoxItems and after setting the desired attributes and values, you could add them to the RadComboBoxItemCollection. Here you could find our help article about using the RadComboBoxItems at server side.

Kind regards,
Nencho
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
ComboBox
Asked by
Mo
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Nencho
Telerik team
Share this question
or