Hello,
I've been searching the forums and found some similar topics but I still can't get it to work so I thought I'd post my own to see what I'm doing wrong.
My situation is simple, I have a ComboBox and I want the dropdown to have checkboxes, as I understand there is no easy way to just add a checkbox to a ComboBox, instead I have to use the ItemTemplate.
At the moment I have a class that uses the ITemplate, it has a InstantiateIn method and there it gets the "dynamic" data from a DB.
It looks something like this, don't mind the extra code it's still very early and just trying to get things to work:
It simply loops over it and takes out all the data, and attaches a Eventhandler
But this doesn't work, the biggest problem is that I don't really get it myself why I have to go on with Templates and all this, I just want a dropdown with checkboxes, so maybe I'm overcomplicating things here or maybe I just don't understand.
Any help is welcome.
I've been searching the forums and found some similar topics but I still can't get it to work so I thought I'd post my own to see what I'm doing wrong.
My situation is simple, I have a ComboBox and I want the dropdown to have checkboxes, as I understand there is no easy way to just add a checkbox to a ComboBox, instead I have to use the ItemTemplate.
At the moment I have a class that uses the ITemplate, it has a InstantiateIn method and there it gets the "dynamic" data from a DB.
It looks something like this, don't mind the extra code it's still very early and just trying to get things to work:
public void InstantiateIn(Control container) { object[] searchoptions = GetProxy().GetSearchOptionList(); DataSet so = (DataSet)searchoptions[0]; List<SearchOption> searchOpt = new List<SearchOption>(); for (int k = 0; k < so.Tables.Count; k++) for (int j = 0; j < so.Tables[k].Rows.Count; j++) { SearchOption search = new SearchOption(); search.ID = so.Tables[k].Rows[j].ItemArray[0].ToString(); search.name = so.Tables[k].Rows[j].ItemArray[1].ToString(); searchOpt.Add(search); CheckBox box = new CheckBox(); box.Text = search.name; box.ID = search.ID; box.DataBinding += new EventHandler(box_DataBinding); container.Controls.Add(box); }}It simply loops over it and takes out all the data, and attaches a Eventhandler
private void box_DataBinding(object sender, EventArgs e) { CheckBox target = (CheckBox)sender; RadComboBoxItem item = (RadComboBoxItem)target.BindingContainer; string itemText = (string)DataBinder.Eval(item, "Text"); target.Text = itemText; }But this doesn't work, the biggest problem is that I don't really get it myself why I have to go on with Templates and all this, I just want a dropdown with checkboxes, so maybe I'm overcomplicating things here or maybe I just don't understand.
Any help is welcome.