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:
If I comment out lines 16 and 17, the combobox behaves appropriately.
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.