DataGrid disappears on UpdateCommand

Discussion in 'ASP .Net Datagrid Control' started by displacer, Apr 23, 2004.

  1. displacer

    displacer Guest

    Hi,

    I'm using a DataGrid with dynmically created colums.
    (AutoGenerateColumns=false)
    I call the DataGrid creation and data binding if !IsPostBack in Page_Load.
    By clicking on Update my DataGrid disappears.

    The strange this is: When I use AutoGenerateColumns=true (not using
    dynmically created columns) everything works fine.

    Can anybody help me out?
    Tom
    displacer, Apr 23, 2004
    #1
    1. Advertising

  2. displacer wrote:

    > Hi,
    >
    > I'm using a DataGrid with dynmically created colums.
    > (AutoGenerateColumns=false)
    > I call the DataGrid creation and data binding if !IsPostBack in Page_Load.
    > By clicking on Update my DataGrid disappears.
    >
    > The strange this is: When I use AutoGenerateColumns=true (not using
    > dynmically created columns) everything works fine.


    I think this is because you are not binding on postbacks and the data is
    being lost. AutoGenerateColumns will generate and bind the columns every
    time the page loads.

    --
    Philip Q
    Microsoft MVP [ASP.NET]
    Philip Q [MVP], Apr 23, 2004
    #2
    1. Advertising

  3. displacer

    tsz Guest

    you mean a call to DataBind()?
    I tried to recreate the DataGrid on every Page_Load but the edit/update
    commands don't work any more.



    "Philip Q [MVP]" <> schrieb im Newsbeitrag
    news:%...
    > displacer wrote:
    >
    > > Hi,
    > >
    > > I'm using a DataGrid with dynmically created colums.
    > > (AutoGenerateColumns=false)
    > > I call the DataGrid creation and data binding if !IsPostBack in

    Page_Load.
    > > By clicking on Update my DataGrid disappears.
    > >
    > > The strange this is: When I use AutoGenerateColumns=true (not using
    > > dynmically created columns) everything works fine.

    >
    > I think this is because you are not binding on postbacks and the data is
    > being lost. AutoGenerateColumns will generate and bind the columns every
    > time the page loads.
    >
    > --
    > Philip Q
    > Microsoft MVP [ASP.NET]
    tsz, Apr 23, 2004
    #3
  4. You've said you are dynamically creating your columns. Since column
    information are not persisted across view states, so you have to make
    sure that you have execute the create column code in every postback. The
    best place to do it would be in the LoadViewState() method of your page.

    To see the explanation and an example, this article might help you:
    http://msdn.microsoft.com/library/d...questionsaboutaspnetdatagridservercontrol.asp

    Hope this help.

    Best Regards,
    Juliet Choy
    Hong Kong
    Microsoft MVP - ASP.NET

    displacer wrote:

    > Hi,
    >
    > I'm using a DataGrid with dynmically created colums.
    > (AutoGenerateColumns=false)
    > I call the DataGrid creation and data binding if !IsPostBack in Page_Load.
    > By clicking on Update my DataGrid disappears.
    >
    > The strange this is: When I use AutoGenerateColumns=true (not using
    > dynmically created columns) everything works fine.
    >
    > Can anybody help me out?
    > Tom
    >
    >
    >
    Juliet Choy [MVP], Apr 26, 2004
    #4
  5. yes u should databind().. to solve the problem.. as philip Q says..

    but u r doing it in the wrong time.. if u do a databind() on postback.. ur
    edit or update command data (posted back) is ignored.
    u should handle the postback event.. the Datagrid_edit() (if u named and
    linked the event that way), and at the end of the code in this event, u shud
    call databind()...

    preferably like below:

    private void Page_Load(object sender, System.EventArgs e)

    {

    if (!IsPostBack)

    BindTaskGrid();

    }

    public void Task_Edit(Object s, DataGridCommandEventArgs e)

    {

    DataGrid1.EditItemIndex=e.Item.ItemIndex;

    BindTaskGrid();

    }

    "tsz" <> wrote in message
    news:...
    > you mean a call to DataBind()?
    > I tried to recreate the DataGrid on every Page_Load but the edit/update
    > commands don't work any more.
    >
    >
    >
    > "Philip Q [MVP]" <> schrieb im Newsbeitrag
    > news:%...
    > > displacer wrote:
    > >
    > > > Hi,
    > > >
    > > > I'm using a DataGrid with dynmically created colums.
    > > > (AutoGenerateColumns=false)
    > > > I call the DataGrid creation and data binding if !IsPostBack in

    > Page_Load.
    > > > By clicking on Update my DataGrid disappears.
    > > >
    > > > The strange this is: When I use AutoGenerateColumns=true (not using
    > > > dynmically created columns) everything works fine.

    > >
    > > I think this is because you are not binding on postbacks and the data is
    > > being lost. AutoGenerateColumns will generate and bind the columns every
    > > time the page loads.
    > >
    > > --
    > > Philip Q
    > > Microsoft MVP [ASP.NET]

    >
    >
    Harish Palaniappan, Apr 26, 2004
    #5
    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. dawn
    Replies:
    1
    Views:
    480
    Daniel Bass
    Jul 28, 2003
  2. Learning SQL Server
    Replies:
    2
    Views:
    2,477
    Learning SQL Server
    Aug 7, 2003
  3. =?Utf-8?B?TmV3YXNwcw==?=
    Replies:
    0
    Views:
    689
    =?Utf-8?B?TmV3YXNwcw==?=
    Jun 12, 2004
  4. srathin

    DataGrid1 UpdateCommand calling DataGrid2 UpdateCommand

    srathin, Apr 9, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    175
    srathin
    Apr 9, 2005
  5. srathin

    DataGrid1 UpdateCommand calling DataGrid2 UpdateCommand

    srathin, Apr 9, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    159
    srathin
    Apr 11, 2005
Loading...

Share This Page