+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Populate repeater when value in drop down list changes

Populate repeater when value in drop down list changes

2 posts, 0 answered
  1. Charles
    Charles avatar
    1 posts
    Registered:
    21 Mar 2014
    10 Apr 2014
    Link to this post

    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();

  2. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    Registered:
    08 Dec 2016
    14 Apr 2014
    Link to this post
    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();
            }

    You can get custom flat taxonomies this way, as well
    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();

    You can find more information about querying and creating dynamic module items from Module Builder -> Your Module -> Code reference for YourModule.
    I hope you find this helpful.

    Regards,
    Nikola Zagorchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
2 posts, 0 answered