1

I have a GridView with records of the database.

I create two DropDown lists dynamically for each selected item. That means, if I click select, two DropDown lists appear, the first one defines a start position, the second one a stop position. Both includes numbers (depending on how many items I have selected). If I have selected 5 items, all DropBox controls include the values 1 - 5. Everything is done by code behind.

Now I want to validate that. The stop Control shall be set to a higher one as the start control. Further more, each area that is already used, is not allowed for the next controls. E. g. if I select in the first pair of DropDown lists the area 1-5, I shall not be able to choose 2-6 with the next pair of controls.

How can I do that. I thought about javascript but that could be very tricky because everything is done with code behind. The validation controls are nice, but I don't know how to validate such a complex thing...

Any Ideas?

Mike Brind
  • 28,238
  • 6
  • 56
  • 88
Stefan
  • 1,253
  • 2
  • 12
  • 36
  • The UI constraints need to be done in Javascript and its associated tools (like jQuery). Once the page has been submitted, the *actual* POST values will need to be validated in the Code Behind. – Robert Harvey Jan 08 '13 at 23:55
  • You might want to look into update panels. Basically put the dropdown lists in an update panel and make sure "Child as trigger" is set. Also set the dropdown lists to autopostback. Now when you change the values of a dropdown list the other list can be updated. You can also set the gridview as a trigger, making sure the update panel is set to trigger conditionally. If you supply some pseudo code I can have a better understanding of what you want and give you an answer in code. – vesuvious Jan 08 '13 at 23:58

1 Answers1

0

thank you for your answers! I dont wont to do a async postback each time, especially because the lists shouldnt be limited during the changes. I solved it in that way: The user clicks on save, I create a bool array for each dropdown item, then I loop through all dropdownlists in the placeholder. If there is a area from 3 - 5 I set the values with index 3-5 in my bool array to true. If one of these values is already true, there must be a wrong selection in the start/stop positions. I think, its not a very nice way but works pretty fast and does everything I want. If someone has a better idea, please let me know... ;)

Thanks! Stefan

Stefan
  • 1,253
  • 2
  • 12
  • 36