(Dynamic Data, ASP.Net, C#, dropdownlists custom .ascx controls ) HOW TO PASS VALUES AMONG DROPDOWNLISTS?

923 views Asked by At

I am working using ASP.Net Dynamic Data, Visual Studio 2010 and C#.

I have three custom controls (FieldTemplates) with extension .ascx: business_type.ascx, department.ascx, section.ascx

If I had selected from the first combo box cod_business type where = 6 I'd like to show only those departments whose cod_business = 6

Lets say that I have 500 departments but only 5, 128 and 446 accomplish that rule.

Let's also say that I have 2,500 sections of which:

  1. 40, 66 and 222 have cod_dept = 5 and cod_business = 6
  2. 346, 399, 400, 403 and 458 have cod_dept = 128 and cod_business = 6
  3. 14, 45, 333 a,d 335 have cod_dept = 446 and cod_business = 6

I'd also like to have displayed in the third combo box only the sections whose cod_business = 6 and whose cod_dept = 5 or 128 or 446, depending on which one had I selected from the department combo box

Remember: This must work on ASP.Net 4.0 Dynamic Data

Is this achievable?

I have seen Cascading solutions from Steve Naughton but they are database oriented.

I need to "connect in its more intrinsic form" the dropdownlists, meaning that I don't have an entity for populating each dropdownlist but the list of values themselves contained inside each dropdownlist. I generally feed these values from small Excel spreadsheets or small text files.

Best regards.

1

There are 1 answers

2
Nathan Anderson On

How are you initially populating the values of the dropdowns? Are they databound controls?

At any rate you are going to need a way to interact with these 3 controls on a postback to achieve your filtering. One way to do this would be to expose the DropDownList as a property on your user control. In your code behind you would add a property similar to this:

public DrowDownList List {
get { return this.DropDownInsideTheControl; }
set { this.DropDownInsideTheControl = value; } }

Add an appropriate event handler to the OnSelectedIndexChanged event and set AutoPostBack to true and you should be good to go. Then the on page containing all the controls you could manage the filtering you desire.

This approach would work, but I think that separating the 3 drop downs into separate user controls is making life harder for you. This these 3 controls are all so closely related, it might make sense to include all of them in the same user control. This way you can interact with them more directly and manage their connected relationship easier. You can still expose the Lists to the Page the control is running in as I outlined above.