Remember values textboxes in datagrid

Discussion in 'ASP .Net' started by Arjen Hoekstra, Aug 16, 2005.

  1. Hello,

    I've got a datagrid with a textbox in each cell. I've also two buttons, one
    to add a row to the datagrid and one to delete a row. A user can type data
    into textboxes and then submit it to a database (by clicking on a submit
    button).
    The problem is that every time, the "add row" or "delete row" button is
    clicked, the textbox values in the datagird are emptied, because when the
    page postbacks it gets the latest datatable from a session variable. Because
    a new datatable is only saved when a new row is added or deleted it will
    have no values every time. Do you have any ideas how to remember the values
    from the textboxes? Thanks in advance for responding.

    Regards,
    Arjen
     
    Arjen Hoekstra, Aug 16, 2005
    #1
    1. Advertising

  2. When populating your DataGrid (i assume in the page_load), ensure to wrap
    this with the if(!Page.IsPostBack) statement

    so

    Page_Load(object s, eventargs e)
    {
    if(!Page.IsPostBack)
    BindGRidFromSession();
    }
    This should prevent the datagrid from repopulating

    Then once you have added or deleted a row, call this method afterwards

    dgDeleteRow()
    {
    //do deleting
    //Reset session - if needed
    BindGridFromSession();
    }

    HTH


    "Arjen Hoekstra" <> wrote in message
    news:ddsn9j$51i$...
    > Hello,
    >
    > I've got a datagrid with a textbox in each cell. I've also two buttons,
    > one to add a row to the datagrid and one to delete a row. A user can type
    > data into textboxes and then submit it to a database (by clicking on a
    > submit button).
    > The problem is that every time, the "add row" or "delete row" button is
    > clicked, the textbox values in the datagird are emptied, because when the
    > page postbacks it gets the latest datatable from a session variable.
    > Because a new datatable is only saved when a new row is added or deleted
    > it will have no values every time. Do you have any ideas how to remember
    > the values from the textboxes? Thanks in advance for responding.
    >
    > Regards,
    > Arjen
    >
     
    Grant Merwitz, Aug 16, 2005
    #2
    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. Replies:
    1
    Views:
    377
    Eliyahu Goldin
    Mar 1, 2006
  2. vishal
    Replies:
    2
    Views:
    1,137
  3. Piotrek \Alchemik\

    [asp c#] remember values after postback

    Piotrek \Alchemik\, Nov 10, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    468
    Piotrek \Alchemik\
    Nov 10, 2006
  4. Frank Miverk
    Replies:
    0
    Views:
    686
    Frank Miverk
    Apr 18, 2007
  5. Erwin Moller
    Replies:
    2
    Views:
    100
    Erwin Moller
    Sep 27, 2005
Loading...

Share This Page