Disappearing Data

  • Thread starter Thread starter Simon
  • Start date Start date
S

Simon

Guys,

I'm populating a dataset and displaying the data in a
datagrid. Then, when the procedure ends the data
disappears. Obviously, this isn't very useful. Any ideas
why this is happening?

Thanks,
Simon.



(code below)

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!IsPostBack)
{
// Attempt 1.
////DataAdapter1.Fill(DataSet1);
////DataGrid1.DataBind();

// Attempt 2.
Connection1.Open();
DataAdapter1.Fill(DataSet1);
DataGrid1.DataSource = DataSet1;
DataGrid1.DataBind();
Connection1.Close();

// At this point I still have data, either way.
}
}

My webpage displays, then I click Button1:

private void Button1_Click(object sender, System.EventArgs
e)
{
// No data in dataset here.
MessageBox.Show(Dataset1.Tables
[0].Rows.Count.ToString());
}
 
Simon,

You'll need to review ASP.NET behavior. When the control returns to the
server, it is totally stupid, has forgotten everything, unless you manage
your state to accomplish something different. That's what stateless means.
One approach to your current problem is to store your dataset in session
state. Depending on what you're doing, this may or may not be the best
approach, but at least it should help you understand the problem.

Kathleen
 
Back
Top