Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DropDownList woes in Dynamic Datagrid

Status
Not open for further replies.

keyser456

IS-IT--Management
Nov 21, 2003
73
US
So I've fought and fought and fought some more, and I've finally got my dynamic DataGrids saving to and loading from viewstate properly... or so I thought.

A quick description of the page. It contains a dynamic # of 4 different types of datagrids. Each row in each datagrid will contain a DropDownList among other controls, so for those columns I used a TemplateColumn that uses a class I created that inherits from ITemplate which adds the DropDownList to the container in ITemplate.InstantiateIn(Control container) method.

So the page loads fine and all my DropDownLists are all full like they should be. However, when I click on my submit button, the page posts back, and all the controls (textboxes and checkboxes) in every row of my datagrid have their correct corresponding data... everything except for the drop down lists, which for some reason have lost their ListItems.

I know there are some fugly work arounds, but I would really like to be able to use the DropDownList.SelectedValue property to be able to find out which item in the drop down list has been selected for each row. It seems like the DropDownList's data must be in ViewState somewhere, but how to have it retrieve that data is eluding me. Any ideas?
 
Looking at the trace info for when the page first loads, I see the Viewstate Size (excluding children) for each of my dynamically created DropDownLists is 0 bytes while the render size fluctuates depending on the # of ListItems it contains. My guess is when the page posts back (and the DropDownList is recreated in the Init section), shortly after in LoadViewState it looks to ViewState for any info related to the control and finds no data so the DropDownList is empty on postback. Hmm... how to make dynamically created drop down lists in rows of dynamically created datagrids use viewstate properly, now that appears to be the question. As I mentioned ealier, all of the other controls in each of the rows are persisting their data just fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top