storing problem

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Andy Cortvriend (andy.cortvriend_at_student.kahosl.be)
Date: 02/17/04


Date: Tue, 17 Feb 2004 13:45:16 +0100

Hi,

I'm developping an asp.net application and i ran to the following problem.
When i press an add button in the aspx page I want to store date in an
datatable. The datatable is created in a seperated class, but every time I
click the button only the last item I added is in that table.
Is this because on the button click a new object of the class is created on
every button click? Is there anyone who could help me to fix the problem?
How can I store the info in the class??

aspx-file

private Tabelletje t = new Tabelletje();

private void Button1_Click(object sender, System.EventArgs e)

{

this.DataGrid1.DataSource =
t.insertResoureInDataTable(Int32.Parse(this.TextBox1.Text),Int32.Parse(this.
TextBox2.Text));

this.DataGrid1.DataBind();

}

class

public class Tabelletje

{

private DataSet ds;

private DataTable table;

private DataColumn col;

private DataRow row;

public Tabelletje()

{

this.createDataTableResources();

}

public void createDataTableResources()

{

ds = new DataSet();

table = new DataTable("test");

col = new DataColumn();

col.DataType = System.Type.GetType("System.Int32");

col.ColumnName = "resID";

table.Columns.Add(col);

col = new DataColumn();

col.DataType = System.Type.GetType("System.Int32");

col.ColumnName = "evrAantal";

table.Columns.Add(col);

ds.Tables.Add(table);

}

public DataSet insertResoureInDataTable(int resID, int aantal)

{

row = table.NewRow();

row["resID"] = resID;

row["evrAantal"] = aantal;

table.Rows.Add(row);

return ds;

}

}

thx


Quantcast