template dataitem on selectedidexchanged

2 posts, 0 answers
  1. Christian
    Christian avatar
    69 posts
    Member since:
    Apr 2008

    Posted 20 Oct 2017 Link to this post

    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??
        }

     

     

     

  2. Eyup
    Admin
    Eyup avatar
    3918 posts

    Posted 25 Oct 2017 Link to this post

    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.
Back to Top