Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RadComboBox adding an item to the top

I am trying to add an item to the top of the drop down. I am using ItemTemplates so i am doing the databind and trying to add one at the top that reads

[ ] All Profiles

I was able to add it, but it is overriding the binding of the actual data, so when i added this now only the [ ] All profiles is there but not the real binded data. What am I doing wrong?

By the way i am a newbie in c# :)

Thank you

  public void BindData()
{
    myCombo.DataSource = myDbConnection.GetValues();
    myCombo.DataTextField = "Name";
    myCombo.DataValueField = "ID";
    myCombo.DataBind();
    var tempProfiles = new[] { new { Name = "All Profiles", ID = "1" } };
    myCombo.DataSource = tempProfiles;
    myCombo.DataBind();

}

<telerik:RadComboBox ID="myCombo" EmptyMessage="All Types" runat="server" Width="200px">
     <ItemTemplate>
       <div onclick="StopPropagation(event)">
         <asp:CheckBox runat="server" ID="chk1" onclick="onCheckBoxClick(this)"/>
              <asp:Label runat="server" ID="lblProfile" AssociatedControlID="chk1">
                  <%# Eval("Name") %>
               </asp:Label>
             </div>
            </ItemTemplate>
            </telerik:RadComboBox> 
like image 517
user710502 Avatar asked Jan 19 '23 06:01

user710502


1 Answers

In your example you're overwriting your DataSourceObject with your 1-item-list.

You should add the item "manually" after your DataBind call:

 myCombo.Items.Insert(0, 
       new Telerik.Web.UI.RadComboBoxItem { Text = "All Profiles", Value = "1" }
    );
 myCombo.SelectedIndex = 0;
like image 79
splattne Avatar answered Jan 30 '23 06:01

splattne