Click here to Skip to main content
15,913,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I have an asp.net data entry page, and everytime the user click button the data just entered will be saved in a temp datatable before actually send to the backend. The code is following:

VB.NET
Imports System.Data.SqlClient

Public Class dt
    Inherits System.Web.UI.Page

            Dim ds As New dsAster

            Dim dtable As DataTable
            Dim r As DataRow

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


    End Sub

Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


        dtable = ds.Tables("dt1")

        r = dtable.NewRow

        r("col1") = Me.TextBox1.Text
        r("col2") = "string=" + Me.TextBox2.Text.ToString

        dtable.Rows.Add(r)

        Me.DataList1.DataSource = dtable
        Me.DataList1.DataBind()


Now the prob is everytime the user click the save button, it will override the one that entered previously. In short, the DataTable will only contain last entered record. What i require is new records will be appended to the datatable.
I think it's because the datatable got created everytime the page load.

What I have tried:

My idea is to not to recreate the datatable if it's not a postback, so I move the declaration portion into page_load in a if not ispostback...end if block, but that will make any vars declare post page_load will not be recognised. Pls help. I've been pulling my hair these past 2 days :(
Thanks guys.
Posted
v2

1 solution

I would suggest you to keep the DataTable in Session and check the Session availability before updating the table.

When you check if that is present, after that you can easily get data from Session and then update the table and assign it back to Session.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900