views:

64

answers:

1

I have a selection list that is generated dynamically, it lists a number of checkboxes that are based on an end-user editable table, as such I have no idea what data, or how much, might be contained in this table and how many checkboxes or what they might contain, other than the primary keys of the table.

The user will select the checks they wish to see, and then control is passed to another page via PostBackUrl. The second page has to figure out which records to show (build it's where clause) based on the checkboxes checked in the previous page.

So, my problem is several-fold. First, asp:CheckBoxes don't have values. This can be worked around by a number of methods. Right now, i'm using a placeholder and dynamically creating the checkboxes in the ItemDataBound event of the DataList. I set the ID to "CheckboxKey1Key2" (where Key1 and Key2 are the primary keys of the check items).

Second, I have to walk through the controls of the PreviousPage to dig out all these values. That in itself is also a pain, but doable.

Now, my thinking is to build the where clause of my Linq2Sql query based on the keys I got from decoding the checked checkbox names. This all seems like a lot of jumping through hoops for something that shouldn't be this difficult. Am I missing something? Does anyone have any better solutions?

A: 

Make a class with a structure for your values that will be useful and easy for you to use on the result page. Then when the user clicks whatever it is they click to go to the result page, loop through the DataList, create a collection from the checked items, and you will only need to grab one object instead of everything, when you need to format your query.

Then when you get to the result page, loop through the collection and build the query in the loop. Pretty easy and not much code.

TheGeekYouNeed
Could you elaborate a bit? I still have to walk through controls of the dynamically created checkboxes, if i'm not mistaken. I am looking for advice on altermate methods that might be more maintainable, if possible.
Mystere Man
You always have to loop through objects if they are dynamically created to get their values.
TheGeekYouNeed