Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

datagrid losing controls on postback

Posted on 2007-11-16
1
553 Views
Last Modified: 2012-06-27
I have a datagrid that auto generates columns set to TRUE.  The general layout of this grid is as follows:

Company 1  |   Company 2 |  Company 3 | Company 4 ....
textbox                 DDL             DDL                 DDL
textbox                 DDL             DDL                 DDL
textbox                 DDL             DDL                 DDL
etc..

the reason im using auto generate is because the column headers are names of companies, and depending on the data that i get back, there will be a variable amount of columns(companies).

so i simply generate a datatable with the correct formating, bind it to the datagrid's datasource,
then on ItemDataBound, i dynamically add controls to the cells which will container either a dropdownlist with data in it, or a textbox (each cell will depend on conditions)

all of this works, however, when i postback on anything, the columns stay, but i lose all my controls.  even if i have it re add those controls on every postback, then i still lose the state of their selected values.
the dropdownlists in the grid do not have autopostback set, so we are posting back on other parts of the page.

is there anything that can be done thats relatively simple?
0
Comment
Question by:mocaiv
1 Comment
 
LVL 37

Accepted Solution

by:
samtran0331 earned 500 total points
ID: 20301298
because of the page lifecyle and when thing like controls and their values get put into viewstate...dynamic controls can get tricky....when you add the controls in ItemDataBound, try wrapping that in an ispostback check...make sure you don't re-add or re-bind the dynamic controls when it is a postback....it might still not be in the correct part of the page lifecycle...but see if it changes your results...
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question