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

Latest version displays EmptyMessage instead of selected item

2 Answers 92 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Aaron Bauman
Top achievements
Rank 1
Aaron Bauman asked on 03 Jan 2012, 09:01 PM
Hello,
I have a simple RadComboBox that when an item is selected it redirects the page back to itself and is supposed to display the item that was selected in the RCB.  
This was working with Web.UI version 2010.3.1109.40, but it broke after upgrading to version 2011.3.1115.40.

With the latest version it will reload the page, but will display the "EmptyMessage" text instead of the selected text.

Here's my page:
<%@ Page Title="Home Page" Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb"
    Inherits="RadComboBoxBug._Default" %>
 
<!DOCTYPE HTML />
<%@ Register TagPrefix="telerik" Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" %>
<html>
    <head id="Head1" runat="server">
        <title>RadComboBox Issues</title>
        <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <form id="Form1" runat="server">
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
            <div class="page">
                <div class="main">
                    <div style="margin: 10px; border: 1px solid #CCC; padding: 10px;">
                        <telerik:RadComboBox ID="RadComboBox2" runat="server" EnableLoadOnDemand="true" EmptyMessage="Select a Person"
                            AppendDataBoundItems="false" AutoPostBack="true" DataValueField="RecordID" DataTextField="Name"
                            ShowMoreResultsBox="true" EnableVirtualScrolling="false" MarkFirstMatch="true"
                            CausesValidation="False" OnClientDropDownOpening="onDropDownOpening" />
                        <asp:Label ID="lbl_SelectedPerson" runat="server" Style="margin-left: 15px" />
                    </div>                    
                </div>
            </div>
        </form>
    </body>
    <script type="text/javascript">
        function onDropDownOpening(sender) {
            var attributes = sender.get_attributes();
            if (attributes.getAttribute("DefaultItem") === "true") {
                sender.requestItems("", false);
                attributes.setAttribute("DefaultItem", "false");
            }
        }
    </script>
</html>

...and the it's code-behind:
Imports Telerik.Web.UI
 
Public Class _Default
    Inherits Page
 
    Private Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        If IsPostBack = False Then
            Dim personID As String = Request.QueryString("PID")
            If personID IsNot Nothing Then
                RadComboBox2.SelectedValue = personID
                RadComboBox2.Attributes.Add("DefaultItem", "true")
                RadComboBox2.Items.Add(New RadComboBoxItem(String.Format("Person {0}", personID), CStr(personID)))
            End If
        End If
    End Sub
 
    Private Sub Page_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender
        lbl_SelectedPerson.Text = String.Format("Selected Item: {0}", RadComboBox2.SelectedValue)
    End Sub
 
    Private Sub RadComboBox2_ItemsRequested(sender As Object, e As RadComboBoxItemsRequestedEventArgs) Handles RadComboBox2.ItemsRequested
        RadComboBox2.DataSource = GetPeople()
        RadComboBox2.DataBind()
        e.EndOfItems = True
    End Sub
 
    Private Sub RadComboBox2_SelectedIndexChanged(sender As Object, e As RadComboBoxSelectedIndexChangedEventArgs) Handles RadComboBox2.SelectedIndexChanged
        Response.Redirect(String.Format("/Default.aspx?PID={0}", e.Value))
    End Sub
 
    Private Function GetPeople() As List(Of Person)
        Dim theList As New List(Of Person)
        For i As Integer = 1 To 100
            theList.Add(New Person() With {.RecordID = i, .Name = String.Format("Person {0}", i)})
        Next
        Return theList
    End Function
 
    Public Structure Person
        Public Property RecordID As Integer
        Public Property Name As String
    End Structure
 
End Class

Does anybody know what's going on with this?

Thanks,
-Aaron

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 04 Jan 2012, 05:15 AM
0
Aaron Bauman
Top achievements
Rank 1
answered on 04 Jan 2012, 02:25 PM
Hi Shinu,
I had seen this thread earlier and had gone over the details of it and tried to do what it said without much luck.  I tried it again and "selected" the appropriate item a different way and it seemed to work this time.  Kind of odd, but nonetheless it's taken care of.

Private Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    If IsPostBack = False Then
        Dim personID As String = Request.QueryString("PID")
        If personID IsNot Nothing Then
            RadComboBox2.Attributes.Add("DefaultItem", "true")
            RadComboBox2.Items.Add(New RadComboBoxItem(String.Format("Person {0}", personID), CStr(personID)))
            RadComboBox2.SelectedValue = personID
        End If
    End If
End Sub


Thanks,
-Aaron
Tags
ComboBox
Asked by
Aaron Bauman
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Aaron Bauman
Top achievements
Rank 1
Share this question
or