Remember values textboxes in datagrid

A

Arjen Hoekstra

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
 
G

Grant Merwitz

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top