Datagrid / Postback Question

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Re: Datagrid / Postback Question

    Craig,

    1) Populate the data grid on page load only:

    If Not IsPostBack Then
    '---Populate your grid the first time.
    End If

    2) Delete the record and then repopulate the grid. (If you do this put the
    routine that populates your grid into a subroutine and call that subroutine
    in the IsPostBack area and call it again after you delete the data.

    Sincerely,

    --
    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    [url]www.aboutfortunate.com[/url]

    "Out of chaos comes order."
    Nietzche


    "Craig S" <craig@removethis_birch.net> wrote in message
    news:Osej5BeXDHA.1004@TK2MSFTNGP12.phx.gbl...
    > I believe the problem is definately a lack of understanding on my part
    about
    > how postbacks work, but here goes...
    >
    > In my Page_Load method I bind my data from a SQL database to a datagrid -
    > works great... I've now created a button and in the OnClick method I do a
    > "DELETE FROM tablename WHERE keyfield=" +variablename (deletes several
    > records based on which checkboxes are checked in the datagrid).
    >
    > The problem is that when the page posts back, the DELETE happens in the
    > database, but it obviously happens after the SELECT statement that
    populates
    > the datagrid. I check the DB contents and the records were indeed
    deleted,
    > but the datagrid is always one postback behind (If I post the page back
    > AGAIN, it will get the update)
    >
    > What code can I add to make sure the datagrid gets bound AFTER the delete
    > command happens?
    >
    > Thanks in advance!
    > Craig
    >
    >
    >

    S. Justin Gengo Guest

  2. Similar Questions and Discussions

    1. Slow datagrid on postback
      Hello there, I have a datagrid that has a select button (so the user can choose a row) and also uses the datagrid sort. If I have a smaller...
    2. UserControl inside of datagrid - loses its viewstate when datagrid is re-bound on postback
      I have a simple usercontrol, a datepicker which contains 3 dropdownlist , it resides inside a datagrid column and i set the selecteddate property of...
    3. custom usercontrol inside of datagrid - loses its state/viewstate on re-bind/postback of the datagrid
      I have a simple usercontrol, a datepicker which contains 3 dropdownlist , it resides inside a datagrid column and i set the selecteddate property of...
    4. Datagrid Postback
      Hello all, I have a Datagrid on a page. 1 column is a template column with a checkbox (unbound). The rest of the columns are databound that are...
    5. Datagrid Postback issues
      Hello all, I have a Datagrid on a page. 1 column is a template column with a checkbox (unbound). The rest of the columns are databound that are...
  3. #2

    Default Re: Datagrid / Postback Question

    Perfect... I'm still used to classic ASP and having to get adjusted :)

    Your advice worked perfectly - thanks...

    "S. Justin Gengo" <sjgengo@aboutfortunate.com> wrote in message
    news:OJ7SsOeXDHA.384@TK2MSFTNGP12.phx.gbl...
    > Craig,
    >
    > 1) Populate the data grid on page load only:
    >
    > If Not IsPostBack Then
    > '---Populate your grid the first time.
    > End If
    >
    > 2) Delete the record and then repopulate the grid. (If you do this put the
    > routine that populates your grid into a subroutine and call that
    subroutine
    > in the IsPostBack area and call it again after you delete the data.
    >
    > Sincerely,
    >
    > --
    > S. Justin Gengo, MCP
    > Web Developer
    >
    > Free code library at:
    > [url]www.aboutfortunate.com[/url]
    >
    > "Out of chaos comes order."
    > Nietzche
    >
    >
    > "Craig S" <craig@removethis_birch.net> wrote in message
    > news:Osej5BeXDHA.1004@TK2MSFTNGP12.phx.gbl...
    > > I believe the problem is definately a lack of understanding on my part
    > about
    > > how postbacks work, but here goes...
    > >
    > > In my Page_Load method I bind my data from a SQL database to a
    datagrid -
    > > works great... I've now created a button and in the OnClick method I do
    a
    > > "DELETE FROM tablename WHERE keyfield=" +variablename (deletes several
    > > records based on which checkboxes are checked in the datagrid).
    > >
    > > The problem is that when the page posts back, the DELETE happens in the
    > > database, but it obviously happens after the SELECT statement that
    > populates
    > > the datagrid. I check the DB contents and the records were indeed
    > deleted,
    > > but the datagrid is always one postback behind (If I post the page back
    > > AGAIN, it will get the update)
    > >
    > > What code can I add to make sure the datagrid gets bound AFTER the
    delete
    > > command happens?
    > >
    > > Thanks in advance!
    > > Craig
    > >
    > >
    > >
    >
    >

    Craig S Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139