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>
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With