DataGrid empty on Postback with ViewState enabled

Discussion in 'ASP .Net Datagrid Control' started by news.acsalaska.net, Jul 3, 2004.

  1. Hi there!

    I'm having a problem with the datagrid control. I can't seem to get the
    datagrid to restore it's contents from ViewState.

    A contributing factor may be the fact that during Page_Init, I mess around
    with the controls collection of the page to programmatically manipulate the
    control tree. I'm doing this in order to control the heirarchy and
    subsequent rendering of controls into the HTML stream. That is needed
    because I'm trying to implement page inheritance for the purposes of
    creating a site derived from templated pages (which eventually derive from
    System.Web.UI.Page). However, at the end of the Initialization phase, the
    control tree looks identical to the control tree sent to the browser (with
    the exception of the child DataGrid controls -- which did in fact exist
    during the first rendering of the page but didn't get recreated when the
    page was posted back).

    If I do a DataBind() in the Page_Load, the child controls in the DataGrid
    can be recreated and contain the data coming from the DataSource. This
    isn't desirable because I want to maintain the flexibility that getting the
    data back from the ViewState normally yields - in particular related to
    editing rows and dealing with dropdown lists in the datagrid's rows.

    Also, if I change my page to directly inherit from System.Web.UI.Page, the
    problem doesn't exist. I think that this demonstrates that I have the
    ViewState enabled correctly. (The other pages participating in the page
    inheritance don't manipulate the ViewState at all).

    Finally, other controls like textboxes and listboxes do in fact maintain
    their data correctly through the postback process. The problem is only
    affecting the DataGrid.

    I read one article stating that the DataGrid actually gets it's ViewState
    refreshed immediately upon being initialized rather than waiting until the
    normal phase of loading view state data. If this is the case, is there a
    way to reapply the DataGrid's ViewState data as I seem to be losing it
    somehow when manipulating the control tree during the Init phase.

    Paul Green
    news.acsalaska.net, Jul 3, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gabor
    Replies:
    3
    Views:
    616
    Jacob Yang [MSFT]
    Aug 26, 2003
  2. Amar
    Replies:
    0
    Views:
    551
  3. Cipher
    Replies:
    3
    Views:
    1,520
    coollzh
    Apr 30, 2004
  4. Fabio Mastria
    Replies:
    5
    Views:
    4,345
    TechMCAD13
    Jan 30, 2008
  5. Amar
    Replies:
    0
    Views:
    220
Loading...

Share This Page