Accessing the items of a ClientItemTemplate

3 posts, 0 answers
  1. SSirica
    SSirica avatar
    54 posts
    Member since:
    Jan 2007

    Posted 28 Dec 2016 Link to this post

    I have the following Combobox setup on my page:

    <telerik:RadComboBox ID="cbxDup" runat="server" Width="350px" DropDownWidth="375px" Height="340px"
        Skin="Default" HighlightTemplatedItems="True" MarkFirstMatch="true"
        AutoPostBack="True" EnableLoadOnDemand="True" EnableVirtualScrolling="True">
        <HeaderTemplate>
            <h2>Codes</h2>
        </HeaderTemplate>
        <ClientItemTemplate>
            <ul class="Main">
                <li><span> #= Text # </span></li>
                <span> #= Attributes.Description # </span>
            </ul>
        </ClientItemTemplate>
        <WebServiceSettings Method="LoadComboBox" Path="SysProf-Add.aspx" />
    </telerik:RadComboBox>

     

    With the following server code:

    <WebMethod()>
    Public Shared Function LoadComboBox(ByVal context As RadComboBoxContext) As RadComboBoxData
        Dim data As DataTable = Nothing
        Dim comboData As New RadComboBoxData()
     
        Try
            data = GetData()
     
            Dim itemOffset As Integer = context.NumberOfItems
            Dim endOffset As Integer = Math.Min(itemOffset + 100, data.Rows.Count)
            comboData.EndOfItems = endOffset = data.Rows.Count
     
            Dim result As New List(Of RadComboBoxItemData)(endOffset - itemOffset)
     
            For Each dr As DataRow In data.Rows
                Dim itemData As New RadComboBoxItemData()
                itemData.Value = dr.Item(0)
                itemData.Text = dr.Item(1)
                itemData.Attributes.Add("Description", dr.Item(2))
                result.Add(itemData)
            Next
     
            comboData.Message = GetStatusMessage(endOffset, data.Rows.Count)
     
            comboData.Items = result.ToArray()
     
            Return comboData
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

     

    What I would like to do is access the Description attribute in the cbxDup.SelectedIndexChanged event?  

     

    Thanks in advance

    Steve

  2. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    319 posts

    Posted 02 Jan Link to this post

    Hi Steve,

    As the RadComboBox in this scenario is bound to a WebMethod, I am afraid that you won't be able to retrieve the Description custom attribute, that is specified for the selected item within the â€‹OnSelectedIndexChanged event handler. What you will have to do instead is to get the selected value:
    Dim selectedvalue As String = e.Value

    And retrieve directly from the DataSource the corresponding Description.

    Regards,
    Veselin Tsvetanov
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. SSirica
    SSirica avatar
    54 posts
    Member since:
    Jan 2007

    Posted 03 Jan in reply to Veselin Tsvetanov Link to this post

    I decided to just suck it up and get the value using Javascript.

    Thanks for the reply anyway.  

Back to Top