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

List of items show up twice in ComboBox

4 Answers 113 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Amanda
Top achievements
Rank 1
Amanda asked on 30 May 2008, 05:46 PM
Hi,

I am having trouble with a RadComboBox that is part of an edit form within a RadGrid.  I am trying to bind a list of items that comes out of a data access layer, but before I bind, I want to add a "Please select a value"-type row as the first row.  I have successfully done this with other forms in my application by first clearing the rows, adding the "please select" row, and then setting .AppendDataBoundItems = true, but I am having trouble this time.  If I remove the two lines that create the new row and set .AppendDataBoundItems = true, the list of values is NOT doubled. 

I am using a function to do this, since I have to do the same action on a number of identical comboboxes with individual labels.  I have verified that my function is only being called once per combobox.  Here is my code:

private void populateAccountControls(GridItemEventArgs e, string labelName, string comboBoxName, string itemName)  
    {  
        RadComboBox mySelect = (RadComboBox)e.Item.FindControl(comboBoxName);  
        Label myLabel = (Label)e.Item.FindControl(labelName);  
 
        if (myLabel != null && mySelect != null)  
        {  
            mySelect.Items.Clear();  
 
            if (itemName!= string.Empty)  
            {  
                myLabel.Text = itemName;  
                myLabel.Visible = true;  
                mySelect.Visible = true;  
 
                mySelect.Items.Insert(0, new RadComboBoxItem("- Please select an account -""-1"));  
                mySelect.AppendDataBoundItems = true;  
 
                DataTable accountList = new DataTable();  
                accountList = Accounts.GetAccounts(itemName);  
                mySelect.DataTextField = "AccountName";  
                mySelect.DataValueField = "AccountID";  
                mySelect.DataSource = accountList;  
                mySelect.DataBind();  
            }  
            else 
            {  
                myLabel.Visible = false;  
                mySelect.Visible = false;  
            }  
        }  
    } 

If I comment out lines 16 and 17, the combobox behaves appropriately.

4 Answers, 1 is accepted

Sort by
0
Rosi
Telerik team
answered on 02 Jun 2008, 01:49 PM
Hello Amanda,

It is really weird, since you say the function executes only once.

Have you tried moving the lines 16 and 17 after calling the mySelect.DataBind() ? Does it make any difference?
Is it possible for you to isolate the problem in a small running project and send it to us in a new support ticket?


All the best,
Rosi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Amanda
Top achievements
Rank 1
answered on 02 Jun 2008, 03:29 PM
I did attempt moving the problem lines to after the call to DataBind(), but it made no difference.  I have compiled a project and will be sending to you.  Thanks.
0
Accepted
Veselin Vasilev
Telerik team
answered on 04 Jun 2008, 01:10 PM
Hello Amanda,

I replied to your support ticket.

You need to populate the comboboxes in the ItemDataBound event handler instead of ItemCreated one.

I think you may find this article helpful:
Distinguishing the major differences between ItemCreated and ItemDataBound


Regards,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Amanda
Top achievements
Rank 1
answered on 04 Jun 2008, 01:57 PM
That fixed it!  Thanks so much for your help.
Tags
ComboBox
Asked by
Amanda
Top achievements
Rank 1
Answers by
Rosi
Telerik team
Amanda
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or