views:

48

answers:

3

Lets say I have three DropDownList controls in a web user control and they depend on each other.

  • Categories
  • Brands
  • Products

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.

  • I can use static variable which is updated once Products selected. That field variable could be public so everyone can reach it
  • Selected Products DropDownList can create a QueryString Field for me to grap the selected value.
  • In the same way, the dropdownlist can create a Session variable on the fly and I can fetch the value
  • It can create a hidden field maybe.

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.

A: 

http://stackoverflow.com/questions/542410/asp-net-pass-value-from-user-control-to-page

brian brinley
Okay, I think there is a misunderstanding here. What I am asking is not how to populate `DropDownList` values but fetching data from `Web User Control` populated by `DropDownList`. Thanks.
Braveyard
you're right after re-reading your question the cascading isnt the problem its the addiitonal filter needed.
brian brinley
A: 

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.

jwiscarson
A: 

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.

ulty4life