Image won't display on selection

2 posts, 0 answers
  1. Johnathan
    Johnathan avatar
    31 posts
    Member since:
    Sep 2012

    Posted 08 Oct 2015 Link to this post

    Hello. I'm working with a raddropdownlist control contained within radfilter and I have this drop down list display images for different each list item. The ImageDropDown image shows you what the display looks like when the drop down list is open. If I select a drop down list item, the item get selected but nothing displays (shown in the MissingSelection Image). However, once I apply the radfilter selection, the image will appear selected on postback (ImageSelected Image). Here's the code-behind code that is used to create the raddropdownlist for the radfilter:

    Protected Sub RadFilter1_ExpressionItemCreated(sender As Object, e As RadFilterExpressionItemCreatedEventArgs) Handles RadFilter1.ExpressionItemCreated
            Dim oConn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("iTask").ConnectionString)
            Dim oCmd As New SqlCommand
            Dim oData As SqlDataReader

            Try
                Dim singleItem As RadFilterSingleExpressionItem = TryCast(e.Item, RadFilterSingleExpressionItem)
                If singleItem IsNot Nothing AndAlso singleItem.FieldName = "Flag" AndAlso singleItem.IsSingleValue Then
                    Dim dropDownList As RadDropDownList = TryCast(singleItem.InputControl, RadDropDownList)
                    oConn.Open()

                    With dropDownList
                        .Width = 50
                        Dim oBlankItem As New DropDownListItem("")
                        .Items.Add(oBlankItem)
                        With oCmd
                            .Parameters.Clear()
                            .Connection = oConn
                            .CommandType = CommandType.StoredProcedure
                            .CommandText = "iTask_Select_Flags"
                        End With
                        oData = oCmd.ExecuteReader
                        Do While oData.Read
                            Dim oItem As New DropDownListItem("")
                            oItem.Text = "<img src='" & CoreComponents.sImageRoot & oData("ImageFileName").ToString & "' style='cursor:pointer;' border='0'/>"
                            oItem.ToolTip = oData("Name").ToString
                            oItem.Value = oData("ImageFileName").ToString
                            'oItem.ImageUrl = CoreComponents.sImageRoot & oData("ImageFileName").ToString
                            .Items.Add(oItem)
                        Loop
                        .OnClientItemSelected = "OnClientItemSelected"
                        '.OnClientSelectedIndexChanged = "OnClientSelectedIndexChanged"
                        .DataBind()
                        oData.Close()

                    End With
                End If
            Catch ex As Exception
            Finally
                oConn.Dispose()
                oConn = Nothing
                oCmd = Nothing
                oData = Nothing
            End Try

        End Sub

     

    I attempted to use the OnClientItemSelected & OnClientSelectedIndexChanged JS code to set the image in the text element of the RadDownDownList control, but to no avail. Here's that code as well. Any help on this issue would be greatly appreciated.

     function OnClientItemSelected(sender, eventArgs) {
                        alert('function called!');
                        var item = eventArgs.get_item();
                        //alert("You selected " + item.get_text() + " with value " + item.get_value());
                        sender.get_textElement().innerHTML = "<img src='<%=CoreComponents.sImageRoot%>" + item.get_value() + "' border='0'/>";
                    }

                    function OnClientSelectedIndexChanged(sender, eventArgs) {
                        alert("You selected item with index : " + eventArgs.get_index());
                        sender.get_textElement().innerHTML = sender.get_items().getItem(eventArgs.get_index()).get_text();
                    }

  2. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 13 Oct 2015 Link to this post

    Hello Johnathan,

    I am afraid that appending the ImageUrl in the textElement of the control is not supported, because the RadDropDownList manages only the text of the element.

    Regards,
    Nencho
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top