Reputation: 81721
Lets say I have three DropDownList
controls in a web user control and they depend on each other.
Explanation:
After I choose a category from Categories dropdown list, related brands are loaded in Brands DropDownList
and same happens when I choose specific brand and they are all located in a web user control since I am using it too much on different pages, I don't want to copy and paste the same code on all the pages.
Problem: The pages can contain a GridView
and DataSource
control which needs an additional Where
parameter to fetch all the data needed in and that parameter could depend on selected product within the Products DropDownList
control.
Question: So how can I get that Selected Product Value from Products DropDownList to bind it to SQLDataSource
or any other DataSource
control.
My Thoughts: I belive I can solve this problem in the ways following.
But: Well those are some of my thoughts but I found them so naive to implement. I need something elegant and satisfying to solve this problem. It should be something like a gateway from the Web User Control to outside world.
Maybe a separate class or a Property can help me in the gateway solution.
Anyways, I am waiting for your answers.
Upvotes: 0
Views: 1042
Reputation: 3012
If I'm understanding the question correctly:
You can add a property to the user control that exposes the products DDL selected value.
You can also add and raise an event from the user control that fires when the products DDL selected value changes. Creating a custom event argument that contains the product value, allows it to get passed directly to the event handler.
Then your pages can handle the event raised by the user control, have the product value, and bind the grid.
Upvotes: 2
Reputation: 2562
You could bind the DropDownList.SelectedIndexChanged events to the same function, and test the SelectedValue properties of each DropDownList. If their SelectedValues are valid, bind the grid to your DataSource.
I've done this in the past when I needed users to input a certain amount of data before I could query the database. I set the Hidden property on my GridView if the DropDownLists weren't valid, and reset it when they were properly bound.
Upvotes: 0