Populate repeater when value in drop down list changes
Hi,
I am an absolute newbie to sitefinity with only two weeks knowledge of sitefinity. I am building a widget to display list of Jobs. My problem is, I want to display list of jobs in a repeater based on the value selected in a dropdown list.
I have three drop down lists that are populated from the taxonomies "Role" "Working Hours" and "Location" . What I simply want to achieve is to display jobs based on the values selected in the drop down. This is currently the code i have in the selected index change event of one of the drop downs. I'd appreciate any help on this issue.
TaxonomyManager taxonomyManager = TaxonomyManager.GetManager();
string role = DropDownRole.Items[DropDownRole.SelectedIndex].Value;
var providername = String.Empty;
DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providername);
Type jobType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Jobs.Job");
var RoleFilteredCollection = dynamicModuleManager.GetDataItems(jobType).Where(jt => jt.GetValue<TrackedList<Guid>>("role-types").Any().Equals(role));
Repeater1.DataSource = RoleFilteredCollection;
Repeater1.DataBind();
Hello Charles,
I suggest subscribing to the dropdowns selectedIndexChanged event , if you are using the Rad Controls Drop down, query the items depending on the dropdown values and rebind the repeater. In the selectedIndexChanged method you can get the selected values from the other two dropdowns, if there are selected values, and use .Where() to filter the items from the query depending on them, or insert your own logic of filtering the items.
Example:
protected
virtual
RadComboBox MyDropDown
get
return
this
.Container.GetControl<RadComboBox>(
"MyDropDown1"
,
true
);
...
protected
override
void
InitializeControls(GenericContainer container)
...
this
.MyDropDown.SelectedIndexChanged+= MyDropDown_SelectedIndexChanged;
protected
void
MyDropDown_SelectedIndexChanged(
object
sender, DropDownListEventArgs e)
if
(MyDropDown.SelectedItem !=
null
)
// query items depending on drop down value
// check other dropdowns
if
(MyDropDown2.SelectedItem !=
null
)
// filter the queried items depending on second drop down choice
...
this
.Repeater.DataSource = items;
this
.Repeater.DataBind();
TaxonomyManager managert = TaxonomyManager.GetManager();
var taxonomy = managert.GetTaxonomies<FlatTaxonomy>().Where(t => t.Name ==
"MyTaxonomyName"
).Single();
var taxa = taxonomy.Taxa.Where(t => t.Title ==
"Title"
).FirstOrDefault();