Manually add items into ItemTemplate

12 posts, 0 answers
  1. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 08 Apr 2013 Link to this post

     

    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

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 08 Apr 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 08 Apr 2013 Link to this post

    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



  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 09 Apr 2013 Link to this post

    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.
  6. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 09 Apr 2013 Link to this post

    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






  7. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 11 Apr 2013 Link to this post

    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.
  8. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 11 Apr 2013 Link to this post

    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
  9. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 16 Apr 2013 Link to this post

    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.
  10. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 16 Apr 2013 Link to this post

    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
  11. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 18 Apr 2013 Link to this post

    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.
  12. Sujath
    Sujath avatar
    2 posts
    Member since:
    Apr 2014

    Posted 10 Jul 2015 Link to this post

    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

  13. Sujath
    Sujath avatar
    2 posts
    Member since:
    Apr 2014

    Posted 10 Jul 2015 Link to this post

    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

     

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017