question about table list in asp.net

A

angus

Dear All,

in my asp.net, i have

- a textbox to input a text
- a "add row" button, after it has been clicked the text in the textbox will
add to the table
- a submit button, the user can add a lot of the rows until submit button is
pressed. during that, the data added in the table will be insert into the
database

here is the screenshot to show the notion

1) an empty table
http://destiny.xfiles.to/ubbthreads/files/615866-1.jpg

2) enter "Row 1" in the textbox and press add row, "Row 1" will be added
into the table
http://destiny.xfiles.to/ubbthreads/files/615867-2.jpg

3) enter "Row 2" in the textbox and press add row, "Row 2" will be added
into the table
http://destiny.xfiles.to/ubbthreads/files/615868-3.jpg

...............etc...............

the data will store into the database after "submit" button has been
pressed.


Here is my background:

I am using the DataTable to store the DataRow and the reord each time add
"row button" has been pressed.
after that, the result datagrid will be updated by the DataTable by binding
the datasource again.

My problem is:

as each time we press the "row button" the form will be repost again. so,
whenever i add the "add row" button,
the previous record added will be empty.

What can i do?

Thank you.


Regards,
scli
 
T

Todd Casey

How are you currently handling the DataTable object during a postback? Are
you storing/retrieving the DataTable object via Page.Session?

Todd Casey
 
A

angus

No, i haven't.
Are you storing/retrieving the DataTable object via Page.Session?

is it in the "Add Row" button listener, write something like

--------------------------------------------------------
Dim dt As New DataTable = Session("dt")

' add rows in datatable

Session("dt") = dt
 
T

Todd Casey

You will need to store the DataTable object so that it is not reset during a
postback. You can use the Page_Load event handler with the combination of
IsPostBack to initialize the DataTable object. Once the DataTable is
initialized you should save that object to the Session. Then on any further
Page_Load events where IsPostBack == true then you can load the DataTable
from the Session.

Does that make sense?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconSessionState.asp

Todd Casey
 
J

John Saunders

angus said:
No, i haven't.


is it in the "Add Row" button listener, write something like

Do not use "New DataTable", just "DataTable". I don't know whether this will
solve your problem, but you'll at least not be creating a new DataTable
object and then immediately replacing it with whatever is in Session("dt").
 

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,781
Messages
2,569,616
Members
45,306
Latest member
TeddyWeath

Latest Threads

Top