Solved

datagrid losing controls on postback

Posted on 2007-11-16
1
548 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now