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

Changing comboBoxItem's text from client side

4 Answers 99 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Sammy78
Top achievements
Rank 2
Sammy78 asked on 23 Jul 2010, 04:51 PM
Hi,

I'm trying to change a ComboBoxItem's text from client side when then text of a radTextBox in another radPanel was changed. It seems to work (partially) but as soon as the page refreshes, I lose all changes and the radComboBox is repopulated with the default values, even though the new values are still present in the textbox. Here is the client side code for the change:
Javascript:
function RefreshPreneursPrenom(sender, args) {
                            var cell = sender.get_element().parentNode.parentNode;
                            var index = cell.parentNode.rowIndex - 1;
                            var prenom = (sender.get_element().value);
 
                            var combo = $find("<%= rcbPreneur.ClientID %>");
                            if (combo != null) {
                                var items = combo.get_items();
                                var comboItem = new Telerik.Web.UI.RadComboBoxItem();
                                var comboItem = items.getItem(index);
 
                                var nomComplet = comboItem.get_text();
                                var nomComplet2 = nomComplet.split("  ");
                                var nomFamille = nomComplet2[1];
                                var nomComplet3 = (prenom.concat("  ", nomFamille));
 
                                comboItem.set_text(nomComplet3);
                                combo.trackChanges();
                                combo.commitChanges();
                                comboItem.Select;
 
                                document.getElementById("<%= rapPreneur.ClientID %>").style.display = 'block';
                            }
                        }

and here's the code that is executed when the panel is being populated:
VB:
Dim i As Int32
        Dim listeAssures As New OCollection(Of Assure)
 
        For i = 0 To NbreVoyageurs - 1
 
            Dim assure As New Assure
            Dim rgItem As GridDataItem = DirectCast(rgDetailsVoyageurs.MasterTableView.Items(i), GridDataItem)
            Dim item As New Telerik.Web.UI.RadComboBoxItem
 
            Dim id As New HiddenField
            id = DirectCast(rgItem("Prenom").FindControl("IDVoyageur" + (i + 1).ToString), HiddenField)
            assure.IDClient = CLng(id.Value)
 
            Dim prenom As New Telerik.Web.UI.RadTextBox
            prenom = DirectCast(rgItem("Prenom").FindControl("PrenomVoyageur" + (i + 1).ToString), Telerik.Web.UI.RadTextBox)
            assure.Prenom = prenom.Text
 
            Dim nom As New Telerik.Web.UI.RadTextBox
            nom = DirectCast(rgItem("Nom").FindControl("NomVoyageur" + (i + 1).ToString), Telerik.Web.UI.RadTextBox)
            assure.Nom = nom.Text
 
            'construction de la date de naissance
            Dim txtJour As New Telerik.Web.UI.RadNumericTextBox
            txtJour = DirectCast(rgItem("Date de naissance").FindControl("DateNaissanceJourVoy" + (i + 1).ToString), Telerik.Web.UI.RadNumericTextBox)
            Dim jourNaissance As Integer = CInt(txtJour.Value)
 
            Dim txtMois As New Telerik.Web.UI.RadComboBox
            txtMois = DirectCast(rgItem("Date de naissance").FindControl("DateNaissanceMoisVoy" + (i + 1).ToString), Telerik.Web.UI.RadComboBox)
            Dim moisNaissance As Integer = CInt(txtMois.SelectedValue.ToString)
 
            Dim txtAnnee As New Telerik.Web.UI.RadNumericTextBox
            txtAnnee = DirectCast(rgItem("Date de naissance").FindControl("DateNaissanceAnVoy" + (i + 1).ToString), Telerik.Web.UI.RadNumericTextBox)
            Dim anneeNaissance As Integer = CInt(txtAnnee.Value)
 
            assure.DateNaissance = New Date(anneeNaissance, moisNaissance, jourNaissance)
 
            Dim checkACharge As New CheckBox
            checkACharge = DirectCast(rgItem("A Charge").FindControl("AChargeVoy" + (i + 1).ToString()), CheckBox)
            assure.IsPersonneACharge = checkACharge.Checked
 
            Dim age As Integer = Today.Year - assure.DateNaissance.Year
 
            If assure.DateNaissance.Month > Today.Month OrElse _
               (assure.DateNaissance.Month = Today.Month AndAlso assure.DateNaissance.Day > Today.Day AndAlso _
                assure.DateNaissance.Day <> Today.Day) Then
                'The current year is not yet complete.
                age -= 1
            End If
 
            If (age > 15) Then
                item.Text = assure.Prenom + "  " + assure.Nom
                item.Value = assure.IDClient.ToString
                rcbPreneur.Items.Add(item)
            End If
 
        Next
 
        Components.AddRange(listeAssures)
 
        rcbPreneur.DataBind()
 
        rapPreneur.Visible = True


Any help would be greatly appreciated
Thank you

Sam

4 Answers, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 23 Jul 2010, 05:13 PM
You should change your if statement to this:

if (combo != null) {
                                var items = combo.get_items();
                                var comboItem = new Telerik.Web.UI.RadComboBoxItem();
                                var comboItem = items.getItem(index);
   
                                var nomComplet = comboItem.get_text();
                                var nomComplet2 = nomComplet.split("  ");
                                var nomFamille = nomComplet2[1];
                                var nomComplet3 = (prenom.concat("  ", nomFamille));
   
                                combo.trackChanges();
                                comboItem.set_text(nomComplet3);
                                comboItem.Select;
                                combo.commitChanges();
   
                                document.getElementById("<%= rapPreneur.ClientID %>").style.display = 'block';
                            }

You called trackChanges() before you made the change and commitChanges() before you selected the item. You need to call trackChanges() before you make any changes and the call commitChanges() after you've made all your changes.

I hope that helps.
0
Sammy78
Top achievements
Rank 2
answered on 26 Jul 2010, 01:10 PM
Hi Cori,
Thanks for pointing out my mistake. Honestly, I had never used these commands (trackchanges and commit), so I just put them in there and tried some things out. But now, with your help, I understand now. :)
I still have a little problem though: If the  value that I'M changing is the one selected in the combobox, the selected change won't change (until postback anyway). The value is alright in the dropdown part though.

Any idea on how to fix this?
Thanks
Sam
0
Sammy78
Top achievements
Rank 2
answered on 27 Jul 2010, 01:25 PM
Anyone have any idea?

Thanks in advance
Sam
0
Sammy78
Top achievements
Rank 2
answered on 27 Jul 2010, 02:23 PM
I've found the solution to my problem!

Javascript:
function RefreshPreneursPrenom(sender, args) {
var cell = sender.get_element().parentNode.parentNode;
var indexGrille = cell.parentNode.rowIndex;
var prenom = (sender.get_element().value);
 
var combo = $find("<%= rcbPreneur.ClientID %>");
if (combo != null) {
var items = combo.get_items();
var comboItem = new Telerik.Web.UI.RadComboBoxItem();
var comboItem = items.getItem(indexGrille);
var comboItemSelectionne = combo.get_selectedItem();
 
var nomComplet = comboItem.get_text();
var nomComplet2 = nomComplet.split("  ");
var nomFamille = nomComplet2[1];
var nomComplet3 = (prenom.concat("  ", nomFamille));
 
combo.trackChanges();
comboItem.set_text(nomComplet3);
combo.updated;
combo.commitChanges();
combo.findItemByValue("zero").select();
comboItemSelectionne.select();
 
document.getElementById("<%= rapPreneur.ClientID %>").style.display = 'block';
}
}

Thanks for the help and for putting me on the right path
Sam
Tags
ComboBox
Asked by
Sammy78
Top achievements
Rank 2
Answers by
Cori
Top achievements
Rank 2
Sammy78
Top achievements
Rank 2
Share this question
or