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

template dataitem on selectedidexchanged

1 Answer 40 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 20 Oct 2017, 01:11 PM

Hi,

I have a Combobox that uses a itemtemplate that is bound to a class object and OnSelectedIndexChanged I need to get the dataitem of that item to get the class object but cant seem to get this to work. Any suggestions? 

 

<telerik:RadComboBox runat="server" ID="cmbOptions" AutoPostBack="true" EmptyMessage="Please select..." OnSelectedIndexChanged="cmbOptions_SelectedIndexChanged">
                                        <ItemTemplate>
                                            <img />
                                            <%#Eval("Text") %>
                                        </ItemTemplate>
                                    </telerik:RadComboBox>

 

private webService.DetailedPart pa;s
private webService.SessUser su;
   webService.SrvCoreClient service;

  

    protected void Page_Load(object sender, EventArgs e)
    {
        su = Common.getSession(Session);
        service = new webService.SrvCoreClient();
 
        pa = service.GetPart(su.id, partId);
 
        if (pa.GroupedParts != null)
        {
            cmbOptions.EmptyMessage = pa.GroupedParts.Header;
            cmbOptions.DataSource = pa.GroupedParts.GroupedParts;
            cmbOptions.DataBind();
        }
    }
 
protected void cmbOptions_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
    {
        //How do I get the dataitem of the selected index??
    }

 

 

 

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 25 Oct 2017, 08:30 AM
Hello Christian,

The DataItems of the individual items is available only during the ItemDataBound event handler. You can use place a asp:Label control inside the ItemTemplate and set the Eval expression to its Text property. Then, you can use the cmbOptions.SelectedItem.FindControl("LabelID") to access the label instance and consequently its Text value.

I hope this will prove helpful.

Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
ComboBox
Asked by
Christian
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or