Hi,
I'm trying to create a combobox dynamically and populate it with data from an XML file.
I am able to get the combobox to show on the page with the first item populated but nothing happens when I click on the arrow to display the rest of the items. (In debug mode I can see that the OnDisplayDatabinding method is being called for every item and that the label is set with the correct data.)
Please take a look at my code and let me know what I'm doing wrong!
Thanks,
Lina
I'm trying to create a combobox dynamically and populate it with data from an XML file.
I am able to get the combobox to show on the page with the first item populated but nothing happens when I click on the arrow to display the rest of the items. (In debug mode I can see that the OnDisplayDatabinding method is being called for every item and that the label is set with the correct data.)
Please take a look at my code and let me know what I'm doing wrong!
Thanks,
Lina
| public partial class DynamicCombo : System.Web.UI.Page |
| { |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| XmlDataSource1.XPath = "/filters/whiteboard/product[@id='WEATHER']/filters/region/option"; |
| //create a new combobox |
| RadComboBox comboBoxRegion = new RadComboBox(); |
| this.Controls.Add(comboBoxRegion); |
| comboBoxRegion.ID = "comboBoxRegion"; |
| comboBoxRegion.DataTextField = "value"; |
| comboBoxRegion.DataSourceID = XmlDataSource1.ID; |
| comboBoxRegion.ItemTemplate = new cbItemTemplate(); |
| comboBoxRegion.DataBind(); |
| } |
| } |
| public class cbItemTemplate : ITemplate |
| { |
| public void InstantiateIn(Control container) |
| { |
| Label label = new Label(); |
| label.ID = "ItemLabel"; |
| label.Text = "Text"; |
| label.DataBinding += new EventHandler(OnDisplayDataBinding); |
| container.Controls.Add(label); |
| } |
| void OnDisplayDataBinding(object sender, EventArgs e) |
| { |
| Label label = (Label)sender; |
| RadComboBoxItem comboboxitem = (RadComboBoxItem)label.BindingContainer; |
| label.Text = (string)DataBinder.Eval(comboboxitem, "Text"); |
| } |
| } |