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

Accessing the items of a ClientItemTemplate

2 Answers 18 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
SSirica
Top achievements
Rank 2
Iron
Iron
Veteran
SSirica asked on 28 Dec 2016, 04:19 PM

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 Answers, 1 is accepted

Sort by
0
Veselin Tsvetanov
Telerik team
answered on 02 Jan 2017, 08:50 AM
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.
0
SSirica
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 03 Jan 2017, 02:49 PM

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

Thanks for the reply anyway.  

Tags
ComboBox
Asked by
SSirica
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Veselin Tsvetanov
Telerik team
SSirica
Top achievements
Rank 2
Iron
Iron
Veteran
Share this question
or