I am sorry if this question seems basic, but I am at a loss. I am new to programming but have enough knowledge to get myself lost. Basically, I have a dropdown list and a repeater list. How do to get the list to change when then categories dropdownd is changed. This is in C#.
Here is the code for the dropdown:
protected void PopulateCategories()
{
category myCategory = new category();
category[] myCategoryList = myCategory.Listing("title ASC");
ddlCategories.Items.Add("-- Select a category --");
ddlCategories.Items.Add("View all categories");
foreach (category category in myCategoryList)
{
ListItem item = new ListItem(category.title, category.category_id);
ddlCategories.Items.Add(item);
}
}
If you need more info please ask. I am new to this and would appreciate any help I can get. Thanks in advance!
You have a couple of options here:
On the dropdownlist control you can add a OnSelectedIndexChanged handler which can update the repeater by databinding a new list to it.
This is easier to do but requires a postback and therefore is not as slick on the client side.
The other way is to handle this in javascript by attaching an event handler to the dropdown list which then updates list. This will be a better experience for the user but will require a bit more effort to either put all the data on the page for all categories or request them as the dropdown changes.