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

Manually add items into ItemTemplate

11 Answers 817 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Andy Green
Top achievements
Rank 2
Andy Green asked on 08 Apr 2013, 01:27 PM

 

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

Sort by
0
Shinu
Top achievements
Rank 2
answered on 08 Apr 2013, 01:49 PM
Hi,

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.
0
Andy Green
Top achievements
Rank 2
answered on 08 Apr 2013, 02:18 PM

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



0
Shinu
Top achievements
Rank 2
answered on 09 Apr 2013, 09:47 AM
Hi,

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.
0
Andy Green
Top achievements
Rank 2
answered on 09 Apr 2013, 11:08 AM
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 With
 
End Sub

I 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






0
Nencho
Telerik team
answered on 11 Apr 2013, 10:51 AM
Hello 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 With



All the best,
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.
0
Andy Green
Top achievements
Rank 2
answered on 11 Apr 2013, 12:34 PM
Thanks Nencho

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
0
Nencho
Telerik team
answered on 16 Apr 2013, 11:22 AM
Hello 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
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.
0
Andy Green
Top achievements
Rank 2
answered on 16 Apr 2013, 11:30 AM
Thanks Nencho

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
0
Nencho
Telerik team
answered on 18 Apr 2013, 02:11 PM
Hello 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
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.
0
Sujath
Top achievements
Rank 1
answered on 10 Jul 2015, 07:11 AM

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

0
Sujath
Top achievements
Rank 1
answered on 10 Jul 2015, 07:12 AM

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

 

Tags
ComboBox
Asked by
Andy Green
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Andy Green
Top achievements
Rank 2
Nencho
Telerik team
Sujath
Top achievements
Rank 1
Share this question
or