Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

datagrid losing controls on postback

Posted on 2007-11-16
1
Medium Priority
?
561 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
[X]
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
1 Comment
 
LVL 37

Accepted Solution

by:
samtran0331 earned 1500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

722 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