Unable to change combobox value

2 posts, 0 answers
  1. Denisas
    Denisas avatar
    9 posts
    Member since:
    Apr 2010

    Posted 18 Oct 2011 Link to this post

    I dynamically create a table with  comboboxes and add it to PlaceHolder.
    private void CreateDynamicTable(string ProductCode)
        RadComboBox combo = new RadComboBox();
        RadComboBoxItem l = new RadComboBoxItem();
        combo.EmptyMessage = "- PASIRINKITE -";
        string[] items = result.Expression.ToString().Split('|');
        string[] values = result.PriceCoefficient.ToString().Split('|');
        int itemsCount = result.Expression.ToString().Count();
        foreach (var item in items.Zip(values, (ix, v) => new { ix, v }))
            l = new RadComboBoxItem(item.ix, item.v);
        tc.Attributes.Add("width", "145px");
        combo.Attributes.Add("Style", "font-family: verdana; width: 140px; font-size : 7pt");
        combo.ID = "cboAttributeName_" + i.ToString();
        combo.ClientIDMode = ClientIDMode.Static;
        combo.OnClientSelectedIndexChanged = "SelectedIndexChanged";
        combo.Attributes.Add("AtributeName", result.AttributeName);
    then I use a js script:
    var attributes_array = new Array();
    function SelectedIndexChanged(sender, eventArgs) {
        var item = eventArgs.get_item();
        var dblCofficient = parseFloat(item.get_value());
        var dblActualPrice = document.getElementById('lblActualPrice').innerHTML;
        if (dblCofficient > 0) {
            var strlblYourPrice = document.getElementById('lblYourPrice').innerHTML;
            var strlblUsualPrice = document.getElementById('lblUsualPrice').innerHTML;
            document.getElementById('lblYourPrice').innerHTML = roundNumber(dblActualPrice * (dblCofficient / 100), 2).toFixed(2).toString().replace(".", ",") + ' Lt.';
            document.getElementById('lblActualPriceDb').innerHTML = roundNumber(dblActualPrice * (dblCofficient / 100), 2).toFixed(2);
            document.getElementById('lblUsualPrice').innerHTML = roundNumber(dblActualPrice * 1.25 * (dblCofficient / 100), 2).toFixed(2).toString().replace(".", ",") + ' Lt.';
        var AtributeName = sender.get_attributes().getAttribute("AtributeName");
        var AtributeValue = item.get_text();
        var field = document.getElementById('txtAttributes').value;
        attributes_array[AtributeName] = AtributeValue;
        var str;
        for (var key in attributes_array) {
            if (attributes_array.hasOwnProperty(key)) {
                str += " " + key + ": " + attributes_array[key] + ";" //существующий формат, или:
        str = str.substr(10);
        document.getElementById('txtAttributes').value = str;

    The problem is, that when I first time select a value in any of dinamically created combo - the value changes, but if I then try to change the value to another - it seems, like it changes, but when combo closes it stays with the value, that was selected first time. I mean, I cannot change selected value. What is wrong?
  2. Ivana
    Ivana avatar
    657 posts

    Posted 21 Oct 2011 Link to this post

    Hi Denisas,

    I did manage to run your code locally, but could not  reproduce the described scenario.

    I have created two RadComboBox controls dynamically, and test them without  the JavaScript code on the page (because I did not have the right elements specified in the JS code). Everything works as expected.

    I have attached the sample page on which I have been testing. Take a look at it, and see if you can reproduce the same scenario.

    If you are still having troubles could you please send a support ticket with a sample page where the scenario in question is illustrated? This way we will be able to test locally the vary same page on which you are getting the described scenario.

    Thank you.

    Kind regards,
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top