Using user input to affect page layout on postback
Posted on 2005-04-05
Ok, that was not the most descriptive title, but my question is kind of specific and I couldn't sum it all up in one line. Here's my problem...
I have a page which contains a number of dynamically generated datagrids. Each datagrid contains rows of data for a group of people... each row representing a person in that group. The number of groups, and hence the number of datagrids, depends on data stored in a database. So, on Page_Load, I go to the database, determine the number of groups, create the datagrids, populate them, and then add them to a placeholder object which is declared in my aspx page. This works fine. I'm running into trouble when I try to alter this data based on user input. One of the columns in the datagrid is a DropDownList which contains the group numbers of the groups on the page. So, if I have 3 group datagrids on the page, the DropDowns contain the numbers 1, 2, and 3. Each of these defaults to its group number... so, the "group 1" dropdowns have '1' selected, the "group 2" dropdowns have '2' selected, etc. Now, I want to have a user be able to move people to different groups by changing their dropdown value to a different group number and the clicking a submit button. When the page is submitted, I want to update the database for the people with altered dropdowns and then reload the page off the new database data. This, however, seems to be easier said than done. When I click submit, the original data is first loaded and THEN the button click method is called. In the button click method I am determining which dropdowns were changed and updating the database accordingly, but this doesn’t really help since the page has already rendered the old data. Furthermore, even if I could get the buttonclick method to execute first, it wouldn’t work because I need to access the datagrids to get at the dropdowns… and the datagrids aren’t created until after Page_Load is called. So I guess my questions are these:
Can I collect the changed dropdown data on the client-side, pass it to the server on submit, alter the database BEFORE Page_Load, and then render the page?
Or, is there some other preferred way of handling this type of situation?
Please help shed some light on this for me!