Hi All
I have a RadCombobox, and the very first item on the list is added in the code behind.
With ddlApptClinic
.Items.Clear()
.Items.Insert(0, New RadComboBoxItem("Any Clinic", -1))
.Items.Insert(0, New RadComboBoxItem("", 0))
I have now added a template item, and the above are missing. How do I add items when I have an item Template
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "ClinicCode")%><br />
<%# DataBinder.Eval(Container.DataItem, "ClinicDescription")%>
</ItemTemplate>
Andy
11 Answers, 1 is accepted
RadComboBox doesn't support adding item using ItemTemplate in aspx and just items programmatic at the same time. Please add items either from ASPX or through code behind.
Thanks,
Shinu.
I was using code behind to add the items as such
With ddlApptClinic
.Items.Clear()
.Items.Insert(0, New RadComboBoxItem("Any Clinic", -1))
.Items.Insert(0, New RadComboBoxItem("", 0))
But since adding an item template this no longer works.
I have since tried your suggestion by adding them in the ASPX and that still don't show.
<telerik:RadComboBox ID="ddlApptClinic" Runat="server" Width="300px" EnableEmbeddedSkins="false" Skin="Activity" emptyMessage=" " AppendDataBoundItems="true" OnDataBound="ddlApptClinic_DataBound"> <HeaderTemplate> <asp:Literal runat="server" ID="ltlClinicCodeHeader" /> </HeaderTemplate> <Items> <telerik:RadComboBoxItem runat="server" Text="Any Clinic" Value="-1" /> <telerik:RadComboBoxItem runat="server" Text="" Value="0" /> </Items> <ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "ClinicCode")%><br /> <span class="clinicStyle"><%# DataBinder.Eval(Container.DataItem, "ClinicDescription")%></span> </ItemTemplate></telerik:RadComboBox>What an I doing wrong?
Andy
I tried your code, I couldn't see the RadCombobox when I set the EmptyMessage=" ". When i removed that property, It works fine for me.
Thanks,
Shinu.
Still not quite right for me.
If I remove the empty message from above I have the following markup: I have also removed the blank item.
<telerik:RadComboBox ID="ddlApptClinic" Runat="server" Width="300px" EnableEmbeddedSkins="false" Skin="Activity" emptyMessage=" " AppendDataBoundItems="true" OnDataBound="ddlApptClinic_DataBound"> <HeaderTemplate> <asp:Literal runat="server" ID="ltlClinicCodeHeader" /> </HeaderTemplate> <Items> <telerik:RadComboBoxItem runat="server" Text="Any Clinic" Value="-1" /> </Items> <ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "ClinicCode")%><br /> <span class="clinicStyle"><%# DataBinder.Eval(Container.DataItem, "ClinicDescription")%></span> </ItemTemplate></telerik:RadComboBox>This is my server side code:
Protected Sub ClinicsBySpecialty(ByVal Specialty_ID As Int32) 'Specialty Dim cl As New Activity_Outcomes Dim cl_ds As Data.DataTable = cl.ClinicsBySpecialty(Specialty_ID, User_GUID) With ddlApptClinic '.Items.Clear() '.Items.Insert(0, New RadComboBoxItem("Any Clinic", -1)) '.Items.Insert(0, New RadComboBoxItem("", 0)) .DataSource = cl_ds .DataTextField = "ClinicCode" .DataValueField = "ClinicId" .DataBind() .SelectedIndex = 0 End WithEnd SubI now get the Any Clinic but not as an item in the list, it only shows in the text box when the control loads. If I make any selection it disappears.
Andy
I would suggest you to call explicitly the DataBind() method, on the manually added item. Please consider the following implementation :
'Specialty Dim cl As New Activity_Outcomes Dim cl_ds As Data.DataTable = cl.ClinicsBySpecialty(Specialty_ID, User_GUID) With ddlApptClinic ddlApptClinic.Items.Clear() ddlApptClinic.DataSource = cl_ds ddlApptClinic.DataTextField = "ClinicCode" ddlApptClinic.DataValueField = "ClinicId" ddlApptClinic.DataBind() Dim item As RadComboBoxItem = New RadComboBoxItem("Any Clinic", "-1") ddlApptClinic.Items.Insert(0, item) item.DataBind() ddlApptClinic.SelectedIndex = 0 End WithAll the best,
Nencho
the Telerik team
But this too adds it to the text box, but not to the list, therefor If I select a clinic I no longer get the option to select Any.
I think for now I'm going to do this in the database, so its in the data that gets bound.
Andy
I am not quite sure that I had understood the issue you are currently facing. Would you elaborate a bit more on the matter? In addition, here is a video demonstrating the behavior at my end with the previously provided implementation.
Kind regards,
Nencho
the Telerik team
The video show exactly what I'm after, but M my implementation does do that. The Any Clinic appears in the text box, but is lost on any selection.
I will revisit and check again
Thanks again Andy
Please take your time investigating the issue further and let us know once you have any results. If the issue still persist, I would suggest you to open a support ticket, along with a runnable sample attached demonstrating the problem, so we could inspect it locally.
Kind regards,
Nencho
the Telerik team
See this link
http://stackoverflow.com/questions/1949424/conditional-item-templates-with-radcombobox
Go through this Documentation Page
http://docs.telerik.com/devtools/aspnet-ajax/controls/combobox/how-to/insert-a-default-item-when-databinding-radcombobox
hello andy green,,
See this link http://stackoverflow.com/questions/1949424/conditional-item-templates-with-radcombobox Go through this Documentation Page http://docs.telerik.com/devtools/aspnet-ajax/controls/combobox/how-to/insert-a-default-item-when-databinding-radcombobox
