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

RadComboBox SelectedValue not updating if selecting item with same text

5 Answers 557 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Callon Campbell
Top achievements
Rank 2
Callon Campbell asked on 13 Aug 2010, 08:00 PM
I have 2 drop downs publisher and heading. If I change the publisher and  select a heading with  a different value but the same text as the previously selected heading the selected value does not update. But if I select a completely different heading with different text and value it works fine.

Here is my code


function PublisherChanged(combo, eventArqs)
{   
    directories.clearSelection()
    headings.clearSelection();
    directories.clearItems(); 
    headings.clearItems(); 
    directories.requestItems('',false);
    headings.requestItems('',false);
                   
}



  private void PopulateHeadings(string publisherName, string text)
        {
          
            if (publisherName == "") return;
            DataTable data = GetHeadings(publisherName, text);
            bool noResults = false;
            if (data.Rows.Count == 0)
            {
                noResults = true;
                DataRow row = data.Rows.Add();
                row["value"] = "[No Results]";
                row["Id"] = "0";
            }

            headings.DataSource = GetTopN(data, 15);
            headings.DataTextField = "value";
            headings.DataValueField = "Id";
            headings.DataBind();


            if (noResults)
            {
                headings.Items[0].Enabled = false;
            }
         
        }

Is the a bug in the control or am I using the control incorrectly?

5 Answers, 1 is accepted

Sort by
0
Kalina
Telerik team
answered on 19 Aug 2010, 11:28 AM
Hello Callon Campbell,

I used the code snippets provided to create a test page and tried reproduce the issue - but unfortunately without success. On my side the RadComboBox updates its selected value correctly - please take a look at this demonstration video. Could you please find the sample attached and give it a try? 

In order to help you we need more information - could you please explain your implementation in more details and send us simplified running page that reproduces the issue?

Can we continue this conversation in the support ticket (ID: 339560) that you have opened?
Thank you in advance.

Greetings,
Kalina
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Billy
Top achievements
Rank 2
answered on 08 Sep 2010, 08:56 PM
Did this get resolved? I am having the same issue. I reviewed the linked video, my situation does not have a "show value" button, the second drop down does a post back and that displays the selected value.

<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="Test.ascx.vb" Inherits="NewInnovations.Demographics.Web.Test" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<telerik:RadComboBox ID="RadComboBox2" runat="server" EmptyMessage="Select a Person"
    EnableLoadOnDemand="true" AppendDataBoundItems="false" AutoPostBack="true" DataTextField="Name"
    DataValueField="RecordID" ShowMoreResultsBox="true" EnableVirtualScrolling="false"
    OnClientDropDownOpening="onDropDownOpening" OnItemsRequested="RadComboBox2_ItemsRequested"
    MarkFirstMatch="true" CausesValidation="False">
</telerik:RadComboBox>
 
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
 
<script type="text/javascript">
    function onDropDownOpening(sender) {
        var attributes = sender.get_attributes();
        if (attributes.getAttribute("DefaultItem") == "true") {
            sender.requestItems("", false);
            attributes.setAttribute("DefaultItem", "false");
        } else if (sender.get_items().get_count() == 0) {
            sender.requestItems("", false);
        }
    }
</script>

Imports Telerik.Web.UI
 
Public Class Test
    Inherits System.Web.UI.UserControl
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If MyBase.IsPostBack = False Then
            'drop down list (selected person)
            RadComboBox2.Attributes.Add("DefaultItem", "true")
            RadComboBox2.Items.Add(New RadComboBoxItem("Billy 1", "1"))
        End If
    End Sub
 
    Protected Sub RadComboBox2_ItemsRequested(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs) Handles RadComboBox2.ItemsRequested
        '
        Dim thePeople As New List(Of Object)
        thePeople.Add(New With {.RecordID = 1, .Name = "Billy 1"})
        thePeople.Add(New With {.RecordID = 2, .Name = "Billy 2"})
        thePeople.Add(New With {.RecordID = 3, .Name = "Billy 2"})
        thePeople.Add(New With {.RecordID = 4, .Name = "Billy 4"})
        '
        RadComboBox2.DataSource = thePeople
        RadComboBox2.DataBind()
        '
        e.EndOfItems = True 'stops "MoreResultsBox" from calling this event again
        '
        e.Message = Me.RadComboBox2.Items.Count & " People"
    End Sub
 
    Private Sub RadComboBox2_SelectedIndexChanged(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) Handles RadComboBox2.SelectedIndexChanged
        Me.Label1.Text = e.Value
    End Sub
End Class
0
Kalina
Telerik team
answered on 14 Sep 2010, 03:59 PM
Hello Billy Hasan,

I used the code provided and created a sample page in order to reproduce the issue with our latest version - Telerik.Web.UI 2010.2.826.20. On my side your code works properly and items with same text are selected correctly - please take a look at this demonstration video.

Let me suggest you download our latest version.

Greetings,
Kalina
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Billy
Top achievements
Rank 2
answered on 22 Oct 2010, 08:52 PM
Alright, I figured out what the problem is. You have to do a redirect on the page in order for it to no longer work. Also I am using version 2010.2 929

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
 
        <telerik:RadComboBox ID="RadComboBox2" runat="server" EmptyMessage="Select a Person"
            EnableLoadOnDemand="true" AppendDataBoundItems="false" AutoPostBack="true" DataTextField="Name"
            DataValueField="RecordID" ShowMoreResultsBox="true" EnableVirtualScrolling="false"
            OnClientDropDownOpening="onDropDownOpening" OnItemsRequested="RadComboBox2_ItemsRequested"
            MarkFirstMatch="true" CausesValidation="False">
        </telerik:RadComboBox>
 
        <asp:Label ID="lblSelectedValue" runat="server"></asp:Label>
    </div>
    </form>
</body>
</html>
 
<script type="text/javascript">
 
    function onDropDownOpening(sender) {
        var attributes = sender.get_attributes();
        if (attributes.getAttribute("DefaultItem") == "true") {
            sender.requestItems("", false);
            attributes.setAttribute("DefaultItem", "false");
        } else if (sender.get_items().get_count() == 0) {
            sender.requestItems("", false);
        }
    }
 
</script>
Imports Telerik.Web.UI
 
Partial Class _Default
    Inherits System.Web.UI.Page
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If MyBase.IsPostBack = False AndAlso Request("Value") IsNot Nothing Then
            'drop down list (selected person)
            RadComboBox2.Attributes.Add("DefaultItem", "true")
            RadComboBox2.Items.Add(New RadComboBoxItem(Request("Text"), Request("Value")))
            '
            Me.lblSelectedValue.Text = Request("Value")
        End If
    End Sub
 
    Protected Sub RadComboBox2_ItemsRequested(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs) Handles RadComboBox2.ItemsRequested
        '
        Dim thePeople As New List(Of Object)
        thePeople.Add(New With {.RecordID = 1, .Name = "Billy1"})
        thePeople.Add(New With {.RecordID = 2, .Name = "Billy2"})
        thePeople.Add(New With {.RecordID = 3, .Name = "Billy2"})
        thePeople.Add(New With {.RecordID = 4, .Name = "Billy4"})
        '
        RadComboBox2.DataSource = thePeople
        RadComboBox2.DataBind()
        '
        e.EndOfItems = True 'stops "MoreResultsBox" from calling this event again
        '
        e.Message = Me.RadComboBox2.Items.Count & " People"
    End Sub
 
    Private Sub RadComboBox2_SelectedIndexChanged(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) Handles RadComboBox2.SelectedIndexChanged
        Dim url As String = String.Format("Default.aspx?Value={0}&Text={1}", e.Value, e.Text)
        Response.Redirect(url)
    End Sub
End Class
0
Kalina
Telerik team
answered on 28 Oct 2010, 09:57 AM
Hi Billy Hasan,

When you redirect the response - in fact you cause a new page load. This means that you lose the state of the page controls stored at ViewState - which is a normal ASP.NET behaviour.
Let me recommend you revise the approach that you use in your implementation.

Kind regards,
Kalina
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
ComboBox
Asked by
Callon Campbell
Top achievements
Rank 2
Answers by
Kalina
Telerik team
Billy
Top achievements
Rank 2
Share this question
or