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

Unable to change combobox value

1 Answer 107 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Denisas
Top achievements
Rank 1
Denisas asked on 18 Oct 2011, 10:25 AM
I dynamically create a table with  comboboxes and add it to PlaceHolder.
private void CreateDynamicTable(string ProductCode)
{
//<skipped>
    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);
        combo.Items.Add(l);
    }
    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);
    tc.Controls.Add(combo);
<skipped>
}
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?

1 Answer, 1 is accepted

Sort by
0
Ivana
Telerik team
answered on 21 Oct 2011, 04:15 PM
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,
Ivana
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
Tags
ComboBox
Asked by
Denisas
Top achievements
Rank 1
Answers by
Ivana
Telerik team
Share this question
or