0

I have a small problem: I am working in asp.net mvc4 and I need to fix this situation:

I have a page with a textbox and multiple dropdown lists. Those dropdown lists' values are related to what the user puts into the textbox. IE:

If in the textbox there's 'foo' I would want ddl1 to be set on 'A', ddl2 on '1' and ddl3 on 'True'.

Those values are bound together into a sql database as the textbox contains the primary key. So I have a database like this:

'foo' (key) , 'A', '1', 'True'
'bar'       , 'B', '1', 'False'
'qux'       , 'C', '2', 'True'

and so on.

I would just want that depending on what is written in the textbox, the page sets the ddls to correspondent values.

tshepang
  • 12,111
  • 21
  • 91
  • 136

2 Answers2

0

Try Knockout or other JavaScript MVVM Binding Framework.

You would have to dump your (currently database) data into JavaScript as JSON then bind it to the proper elements.

See here: http://knockoutjs.com/

haim770
  • 48,394
  • 7
  • 105
  • 133
0

Depending on how many rows you have in the DB, the first thing you should do is get all of them and cache the data so you don't have a DB request for every ddl.

Then you need to decide which event to catch for the textbox. I'd recommend you use the KeyUp (filtering for Tab or Enter).

In this eventhandler you then change the SelectedValueof the first ddl and explicitly fire the "SelectedValueChanged" for it (check if this has to be done explicitly).

This way you can cascade through all of the ddls you have.

I'm not sure what the best way for storing the values would be. You could either create a class which handles also the relations or use several lists (very losely coupled). The first would surely be the better solutin.

Markus Deibel
  • 1,261
  • 20
  • 26